Search in sources :

Example 21 with GapicProductConfig

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

the class StaticLangGapicSamplesTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel apiModel, GapicProductConfig productConfig) {
    String packageName = productConfig.getPackageName();
    SurfaceNamer namer = newSurfaceNamer.apply(productConfig);
    ModelTypeTable typeTable = newTypeTable.apply(packageName);
    FeatureConfig featureConfig = newFeatureConfig.apply(productConfig);
    List<InterfaceContext> interfaceContexts = Streams.stream(apiModel.getInterfaces(productConfig)).filter(iface -> productConfig.hasInterfaceConfig(iface)).map(iface -> GapicInterfaceContext.create(iface, productConfig, typeTable, namer, featureConfig)).collect(ImmutableList.toImmutableList());
    ImmutableTable<String, String, ImmutableList<SampleConfig>> sampleConfigTable = productConfig.getSampleConfigTable();
    List<ViewModel> sampleFiles;
    if (sampleConfigTable.isEmpty()) {
        // We don't have sample configs. Continue to use gapic config.
        sampleFiles = generateSamplesFromGapicConfigs(interfaceContexts, productConfig, namer);
    } else {
        // Generate samples using sample configs.
        sampleFiles = generateSamplesFromSampleConfigs(interfaceContexts, productConfig);
    }
    if (!interfaceContexts.isEmpty() && !sampleFiles.isEmpty()) {
        ViewModel entryPoint = generateSampleEntryPoint(interfaceContexts.get(0));
        if (entryPoint != null) {
            sampleFiles.add(entryPoint);
        }
    }
    return ImmutableList.copyOf(sampleFiles);
}
Also used : Arrays(java.util.Arrays) HashMap(java.util.HashMap) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) Function(java.util.function.Function) ArrayList(java.util.ArrayList) InterfaceContext(com.google.api.codegen.config.InterfaceContext) SampleEntryPointView(com.google.api.codegen.viewmodel.SampleEntryPointView) MethodSampleView(com.google.api.codegen.viewmodel.MethodSampleView) ImmutableList(com.google.common.collect.ImmutableList) MethodContext(com.google.api.codegen.config.MethodContext) MethodModel(com.google.api.codegen.config.MethodModel) ViewModel(com.google.api.codegen.viewmodel.ViewModel) Map(java.util.Map) StaticLangSampleClassView(com.google.api.codegen.viewmodel.StaticLangSampleClassView) StaticLangFileView(com.google.api.codegen.viewmodel.StaticLangFileView) SampleConfig(com.google.api.codegen.config.SampleConfig) Nullable(javax.annotation.Nullable) GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType) SampleContext(com.google.api.codegen.config.SampleContext) CallingForm(com.google.api.codegen.viewmodel.CallingForm) Streams(com.google.common.collect.Streams) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) List(java.util.List) Paths(java.nio.file.Paths) SampleSpec(com.google.api.codegen.config.SampleSpec) ImmutableTable(com.google.common.collect.ImmutableTable) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) ImmutableList(com.google.common.collect.ImmutableList) InterfaceContext(com.google.api.codegen.config.InterfaceContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 22 with GapicProductConfig

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

the class CSharpBasicPackageTransformer method generateCsproj.

private SimpleInitFileView generateCsproj(GapicInterfaceContext context) {
    GapicProductConfig productConfig = context.getProductConfig();
    String outputPath = pathMapper.getOutputPath(context.getInterface().getFullName(), productConfig);
    return SimpleInitFileView.create(templateFilename, outputPath + File.separator + productConfig.getPackageName() + fileBaseSuffix, fileHeaderTransformer.generateFileHeader(context));
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig)

Example 23 with GapicProductConfig

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

the class DynamicLangGapicSamplesTransformer method generateSamplesFromGapicConfigs.

private List<ViewModel> generateSamplesFromGapicConfigs(List<InterfaceContext> interfaceContexts, GapicProductConfig productConfig, SurfaceNamer namer) {
    List<MethodSampleView> allSamples = interfaceContexts.stream().flatMap(c -> apiMethodTransformer.generateApiMethods(c).stream()).flatMap(m -> m.samples().stream()).collect(ImmutableList.toImmutableList());
    SampleFileRegistry registry = new SampleFileRegistry(namer, allSamples);
    ImmutableList.Builder<ViewModel> sampleFileViews = ImmutableList.builder();
    for (InterfaceContext context : interfaceContexts) {
        List<OptionalArrayMethodView> methods = apiMethodTransformer.generateApiMethods(context);
        for (OptionalArrayMethodView method : methods) {
            for (MethodSampleView sample : method.samples()) {
                sampleFileViews.add(newSampleFileView(productConfig, context, registry.getSampleFileName(sample, method.name()), method, sample));
            }
        }
    }
    return sampleFileViews.build();
}
Also used : Arrays(java.util.Arrays) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) InterfaceContext(com.google.api.codegen.config.InterfaceContext) MethodSampleView(com.google.api.codegen.viewmodel.MethodSampleView) ImmutableList(com.google.common.collect.ImmutableList) MethodContext(com.google.api.codegen.config.MethodContext) MethodModel(com.google.api.codegen.config.MethodModel) ViewModel(com.google.api.codegen.viewmodel.ViewModel) Map(java.util.Map) DynamicLangSampleView(com.google.api.codegen.viewmodel.DynamicLangSampleView) SampleConfig(com.google.api.codegen.config.SampleConfig) GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) SampleContext(com.google.api.codegen.config.SampleContext) CallingForm(com.google.api.codegen.viewmodel.CallingForm) Streams(com.google.common.collect.Streams) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) List(java.util.List) Paths(java.nio.file.Paths) SampleSpec(com.google.api.codegen.config.SampleSpec) ImmutableTable(com.google.common.collect.ImmutableTable) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) MethodSampleView(com.google.api.codegen.viewmodel.MethodSampleView) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) ImmutableList(com.google.common.collect.ImmutableList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceContext(com.google.api.codegen.config.InterfaceContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext)

Example 24 with GapicProductConfig

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

the class NodeJSSamplePackageMetadataTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
    boolean shouldGenerateSamplePackages = productConfig.getInterfaceConfigMap().values().stream().flatMap(config -> config.getMethodConfigs().stream()).anyMatch(config -> config.getSampleSpec().isConfigured());
    if (!shouldGenerateSamplePackages) {
        return Collections.emptyList();
    }
    NodeJSPackageMetadataNamer gapicPackageNamer = new NodeJSPackageMetadataNamer(productConfig.getPackageName(), productConfig.getDomainLayerLocation());
    String outputPath = "samples/package.json";
    ViewModel metadataView = metadataTransformer.generateMetadataView(gapicPackageNamer, packageConfig, model, TEMPLATE_FILE, outputPath, TargetLanguage.NODEJS).identifier(samplePackageIdentifier(productConfig)).hasMultipleServices(model.hasMultipleServices()).additionalDependencies(additionalDependencies(gapicPackageNamer)).build();
    return Collections.singletonList(metadataView);
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) List(java.util.List) PackageMetadataTransformer(com.google.api.codegen.transformer.PackageMetadataTransformer) PackageMetadataConfig(com.google.api.codegen.config.PackageMetadataConfig) ImmutableList(com.google.common.collect.ImmutableList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) TargetLanguage(com.google.api.codegen.common.TargetLanguage) PackageDependencyView(com.google.api.codegen.viewmodel.metadata.PackageDependencyView) Collections(java.util.Collections) VersionBound(com.google.api.codegen.config.VersionBound) ModelToViewTransformer(com.google.api.codegen.transformer.ModelToViewTransformer) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Aggregations

GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)24 PackageMetadataConfig (com.google.api.codegen.config.PackageMetadataConfig)11 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)10 ViewModel (com.google.api.codegen.viewmodel.ViewModel)9 List (java.util.List)8 ArrayList (java.util.ArrayList)7 ImmutableList (com.google.common.collect.ImmutableList)6 TargetLanguage (com.google.api.codegen.common.TargetLanguage)5 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)5 InterfaceContext (com.google.api.codegen.config.InterfaceContext)5 MethodModel (com.google.api.codegen.config.MethodModel)5 Model (com.google.api.tools.framework.model.Model)5 Map (java.util.Map)5 Function (java.util.function.Function)5 CodeGenerator (com.google.api.codegen.common.CodeGenerator)4 SampleContext (com.google.api.codegen.config.SampleContext)4 GapicCodePathMapper (com.google.api.codegen.gapic.GapicCodePathMapper)4 GapicGeneratorConfig (com.google.api.codegen.gapic.GapicGeneratorConfig)4 Streams (com.google.common.collect.Streams)4 Paths (java.nio.file.Paths)4