Search in sources :

Example 6 with InterfaceContext

use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.

the class JavaApiMethodTransformer method generateLongRunningMethods.

private List<StaticLangApiMethodView> generateLongRunningMethods(MethodContext methodContext, @Nullable SampleContext sampleContext) {
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    InterfaceContext interfaceContext = methodContext.getSurfaceInterfaceContext();
    interfaceContext.getImportTypeTable().saveNicknameFor("com.google.api.gax.rpc.OperationCallable");
    MethodConfig methodConfig = methodContext.getMethodConfig();
    if (methodConfig.isFlattening()) {
        List<FlatteningConfig> flatteningConfigs = FlatteningConfig.withRepeatedResourceInSampleOnly(methodConfig.getFlatteningConfigs());
        for (FlatteningConfig flatteningGroup : flatteningConfigs) {
            MethodContext flattenedMethodContext = interfaceContext.asFlattenedMethodContext(methodContext, flatteningGroup).withCallingForms(Collections.singletonList(CallingForm.LongRunningFlattenedAsync));
            apiMethods.add(generateAsyncOperationFlattenedMethod(flattenedMethodContext, sampleContext));
        }
    }
    apiMethods.add(generateAsyncOperationRequestObjectMethod(methodContext.withCallingForms(Collections.singletonList(CallingForm.LongRunningRequestAsync)), sampleContext));
    apiMethods.add(generateOperationCallableMethod(methodContext.withCallingForms(Collections.singletonList(CallingForm.LongRunningCallable)), sampleContext));
    apiMethods.add(generateCallableMethod(methodContext.withCallingForms(Collections.singletonList(CallingForm.Callable)), sampleContext));
    return apiMethods;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ArrayList(java.util.ArrayList) MethodContext(com.google.api.codegen.config.MethodContext) InterfaceContext(com.google.api.codegen.config.InterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 7 with InterfaceContext

use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.

the class JavaApiMethodTransformer method generateUnaryMethods.

private List<StaticLangApiMethodView> generateUnaryMethods(MethodContext methodContext, @Nullable SampleContext sampleContext) {
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    InterfaceContext interfaceContext = methodContext.getSurfaceInterfaceContext();
    MethodConfig methodConfig = methodContext.getMethodConfig();
    if (methodConfig.isFlattening()) {
        List<FlatteningConfig> flatteningConfigs = FlatteningConfig.withRepeatedResourceInSampleOnly(methodConfig.getFlatteningConfigs());
        for (FlatteningConfig flatteningGroup : flatteningConfigs) {
            MethodContext flattenedMethodContext = interfaceContext.asFlattenedMethodContext(methodContext, flatteningGroup);
            apiMethods.add(generateFlattenedMethod(flattenedMethodContext.withCallingForms(Collections.singletonList(CallingForm.Flattened)), sampleContext));
        }
    }
    apiMethods.add(generateRequestObjectMethod(methodContext.withCallingForms(Collections.singletonList(CallingForm.Request)), sampleContext));
    apiMethods.add(generateCallableMethod(methodContext.withCallingForms(Collections.singletonList(CallingForm.Callable)), sampleContext));
    return apiMethods;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ArrayList(java.util.ArrayList) MethodContext(com.google.api.codegen.config.MethodContext) InterfaceContext(com.google.api.codegen.config.InterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 8 with InterfaceContext

use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.

the class JavaApiMethodTransformer method generatePagedStreamingMethods.

private List<StaticLangApiMethodView> generatePagedStreamingMethods(MethodContext methodContext, @Nullable SampleContext sampleContext) {
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    InterfaceContext interfaceContext = methodContext.getSurfaceInterfaceContext();
    MethodConfig methodConfig = methodContext.getMethodConfig();
    if (methodConfig.isFlattening()) {
        List<FlatteningConfig> flatteningConfigs = FlatteningConfig.withRepeatedResourceInSampleOnly(methodConfig.getFlatteningConfigs());
        for (FlatteningConfig flatteningGroup : flatteningConfigs) {
            MethodContext flattenedMethodContext = interfaceContext.asFlattenedMethodContext(methodContext, flatteningGroup).withCallingForms(ImmutableList.of(CallingForm.FlattenedPaged));
            apiMethods.add(generatePagedFlattenedMethod(flattenedMethodContext, sampleContext));
        }
    }
    apiMethods.add(generatePagedRequestObjectMethod(methodContext.withCallingForms(ImmutableList.of(CallingForm.RequestPaged)), sampleContext));
    apiMethods.add(generatePagedCallableMethod(methodContext.withCallingForms(ImmutableList.of(CallingForm.CallablePaged)), sampleContext));
    apiMethods.add(generateUnpagedListCallableMethod(methodContext.withCallingForms(Collections.singletonList(CallingForm.CallableList)), sampleContext));
    return apiMethods;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ArrayList(java.util.ArrayList) MethodContext(com.google.api.codegen.config.MethodContext) InterfaceContext(com.google.api.codegen.config.InterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 9 with InterfaceContext

use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.

the class SampleManifestTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer surfaceNamer = newSurfaceNamer.apply(productConfig);
    ModelTypeTable typeTable = newTypeTable.apply(productConfig.getPackageName());
    FeatureConfig featureConfig = newFeatureConfig.apply(productConfig);
    ImmutableList.Builder<SampleManifestView.SampleEntry> builder = ImmutableList.builder();
    List<InterfaceContext> interfaceContexts = Streams.stream(model.getInterfaces(productConfig)).filter(iface -> productConfig.hasInterfaceConfig(iface)).map(iface -> GapicInterfaceContext.create(iface, productConfig, typeTable, surfaceNamer, featureConfig)).collect(ImmutableList.toImmutableList());
    List<SampleContext> sampleContexts = metadataNamer.getSampleContexts(interfaceContexts, productConfig);
    for (SampleContext context : sampleContexts) {
        String sample = context.uniqueSampleId();
        String path = metadataNamer.getSamplePath(sample);
        String regionTag = context.sampleConfig().regionTag();
        String className = metadataNamer.getSampleClassName(sample);
        builder.add(SampleManifestView.SampleEntry.create(sample, path, className, regionTag));
    }
    ImmutableList<SampleManifestView.SampleEntry> entries = builder.build();
    // Only generate manifest files when samples are configured through sample config.
    if (entries.isEmpty()) {
        return Collections.emptyList();
    }
    SampleManifestView.Builder sampleManifestView = SampleManifestView.newBuilder();
    sampleManifestView.environment(metadataNamer.getEnvironment());
    sampleManifestView.bin(metadataNamer.getBin());
    sampleManifestView.basePath(metadataNamer.getBasePath(productConfig));
    sampleManifestView.packageName(metadataNamer.getPackageName(productConfig));
    sampleManifestView.invocation(metadataNamer.getInvocation());
    sampleManifestView.schemaVersion(MANIFEST_SCHEMA_VERSION);
    sampleManifestView.sampleEntries(entries);
    sampleManifestView.outputPath(getManifestOutputPath(model, productConfig));
    sampleManifestView.templateFileName(TEMPLATE_NAME);
    return Collections.singletonList(sampleManifestView.build());
}
Also used : GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) SampleContext(com.google.api.codegen.config.SampleContext) Streams(com.google.common.collect.Streams) Function(java.util.function.Function) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) InterfaceContext(com.google.api.codegen.config.InterfaceContext) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) SampleManifestView(com.google.api.codegen.viewmodel.metadata.SampleManifestView) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Paths(java.nio.file.Paths) ViewModel(com.google.api.codegen.viewmodel.ViewModel) VersionMatcher(com.google.api.codegen.util.VersionMatcher) Splitter(com.google.common.base.Splitter) Collections(java.util.Collections) ImmutableList(com.google.common.collect.ImmutableList) InterfaceContext(com.google.api.codegen.config.InterfaceContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) SampleManifestView(com.google.api.codegen.viewmodel.metadata.SampleManifestView) SampleContext(com.google.api.codegen.config.SampleContext)

Example 10 with InterfaceContext

use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.

the class RubyPackageMetadataTransformer method generateMetadataView.

private ViewModel generateMetadataView(ApiModel model, GapicProductConfig productConfig, String template, RubyPackageMetadataNamer namer, String filePrefix) {
    String noLeadingRubyDir = template.startsWith(RUBY_PREFIX) ? template.substring(RUBY_PREFIX.length()) : template;
    if (!Strings.isNullOrEmpty(filePrefix)) {
        noLeadingRubyDir = filePrefix + noLeadingRubyDir;
    }
    int extensionIndex = noLeadingRubyDir.lastIndexOf(".");
    String outputPath = noLeadingRubyDir.substring(0, extensionIndex);
    Collection<InterfaceModel> interfaceModels = model.getInterfaces(productConfig).stream().filter(productConfig::hasInterfaceConfig).collect(ImmutableList.toImmutableList());
    List<GapicInterfaceContext> contexts = interfaceModels.stream().map(i -> createContext(i, productConfig)).collect(ImmutableList.toImmutableList());
    boolean hasSmokeTests = contexts.stream().map(InterfaceContext::getInterfaceConfig).map(InterfaceConfig::getSmokeTestConfig).anyMatch(Objects::nonNull);
    SurfaceNamer surfaceNamer = new RubySurfaceNamer(productConfig.getPackageName());
    ImportSectionView importSection = importSectionTransformer.generateRakefileAcceptanceTaskImportSection(contexts);
    return metadataTransformer.generateMetadataView(namer, packageConfig, model, template, outputPath, TargetLanguage.RUBY).identifier(namer.getMetadataIdentifier()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, surfaceNamer)).hasSmokeTests(hasSmokeTests).versionPath(surfaceNamer.getVersionIndexFileImportName()).versionNamespace(validVersionNamespace(interfaceModels, surfaceNamer)).credentialsClassName(surfaceNamer.getFullyQualifiedCredentialsClassName()).smokeTestProjectVariable(namer.getProjectVariable(true)).smokeTestKeyfileVariable(namer.getKeyfileVariable(true)).smokeTestJsonKeyVariable(namer.getJsonKeyVariable(true)).projectVariable(namer.getProjectVariable(false)).jsonKeyVariable(namer.getJsonKeyVariable(false)).build();
}
Also used : PackageMetadataConfig(com.google.api.codegen.config.PackageMetadataConfig) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) TestCaseTransformer(com.google.api.codegen.transformer.TestCaseTransformer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView) RubyTypeTable(com.google.api.codegen.util.ruby.RubyTypeTable) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) HashSet(java.util.HashSet) InterfaceContext(com.google.api.codegen.config.InterfaceContext) Strings(com.google.common.base.Strings) ImmutableList(com.google.common.collect.ImmutableList) MethodModel(com.google.api.codegen.config.MethodModel) ViewModel(com.google.api.codegen.viewmodel.ViewModel) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) TargetLanguage(com.google.api.codegen.common.TargetLanguage) ValueProducer(com.google.api.codegen.util.testing.ValueProducer) PackageMetadataTransformer(com.google.api.codegen.transformer.PackageMetadataTransformer) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView) ImmutableSet(com.google.common.collect.ImmutableSet) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) TocContentView(com.google.api.codegen.viewmodel.metadata.TocContentView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StandardValueProducer(com.google.api.codegen.util.testing.StandardValueProducer) Collection(java.util.Collection) Set(java.util.Set) FileHeaderTransformer(com.google.api.codegen.transformer.FileHeaderTransformer) PackageDependencyView(com.google.api.codegen.viewmodel.metadata.PackageDependencyView) ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) DynamicLangApiMethodTransformer(com.google.api.codegen.transformer.DynamicLangApiMethodTransformer) InitCodeTransformer(com.google.api.codegen.transformer.InitCodeTransformer) List(java.util.List) ApiModel(com.google.api.codegen.config.ApiModel) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ReadmeMetadataView(com.google.api.codegen.viewmodel.metadata.ReadmeMetadataView) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ModelToViewTransformer(com.google.api.codegen.transformer.ModelToViewTransformer) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) InterfaceContext(com.google.api.codegen.config.InterfaceContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) InterfaceModel(com.google.api.codegen.config.InterfaceModel) Objects(java.util.Objects) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

InterfaceContext (com.google.api.codegen.config.InterfaceContext)18 ArrayList (java.util.ArrayList)13 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)11 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)10 ViewModel (com.google.api.codegen.viewmodel.ViewModel)10 MethodContext (com.google.api.codegen.config.MethodContext)9 SampleContext (com.google.api.codegen.config.SampleContext)8 ImmutableList (com.google.common.collect.ImmutableList)8 List (java.util.List)8 MethodModel (com.google.api.codegen.config.MethodModel)7 CallingForm (com.google.api.codegen.viewmodel.CallingForm)7 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)6 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)6 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)6 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)5 MethodConfig (com.google.api.codegen.config.MethodConfig)5 SampleConfig (com.google.api.codegen.config.SampleConfig)5 GapicCodePathMapper (com.google.api.codegen.gapic.GapicCodePathMapper)5 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)5 HashMap (java.util.HashMap)5