Search in sources :

Example 1 with GapicProductConfig

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

the class CSharpGapicClientTransformer method generateCsProjView.

private PackageInfoView generateCsProjView(GapicInterfaceContext context) {
    Model model = context.getModel();
    GapicProductConfig productConfig = context.getProductConfig();
    PackageInfoView.Builder view = PackageInfoView.newBuilder();
    view.templateFileName(CSPROJ_TEMPLATE_FILENAME);
    String outputPath = pathMapper.getOutputPath(context.getInterface().getFullName(), productConfig);
    view.outputPath(outputPath + File.separator + productConfig.getPackageName() + ".csproj");
    view.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    view.serviceTitle(model.getServiceConfig().getTitle());
    view.serviceDescription(model.getServiceConfig().getDocumentation().getSummary().trim());
    view.domainLayerLocation(productConfig.getDomainLayerLocation());
    // Unused in C#
    view.authScopes(new ArrayList<String>());
    view.releaseLevel(productConfig.getReleaseLevel());
    String versionSuffix;
    switch(productConfig.getReleaseLevel()) {
        case ALPHA:
            versionSuffix = "-alpha01";
            break;
        case BETA:
            versionSuffix = "-beta01";
            break;
        default:
            versionSuffix = "";
            break;
    }
    view.version("1.0.0" + versionSuffix);
    String tags = "";
    for (String tag : Splitter.on('.').split(productConfig.getPackageName())) {
        if (tag.matches("[vV][\\d.]+")) {
            break;
        }
        tags += ";" + tag;
    }
    view.tags(tags.isEmpty() ? "" : tags.substring(1));
    view.packageMetadata(generatePackageMetadataView(context));
    view.serviceDocs(new ArrayList<ServiceDocView>());
    return view.build();
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ServiceDocView(com.google.api.codegen.viewmodel.ServiceDocView) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceModel(com.google.api.codegen.config.InterfaceModel) MethodModel(com.google.api.codegen.config.MethodModel) ApiModel(com.google.api.codegen.config.ApiModel) Model(com.google.api.tools.framework.model.Model) PackageInfoView(com.google.api.codegen.viewmodel.PackageInfoView)

Example 2 with GapicProductConfig

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

the class CSharpGapicUnitTestTransformer method generateUnitTestCsproj.

private ClientTestFileView generateUnitTestCsproj(GapicInterfaceContext context) {
    ClientTestFileView.Builder builder = generateUnitTestBuilder(context);
    GapicProductConfig productConfig = context.getProductConfig();
    String outputPath = pathMapper.getOutputPath(context.getInterface().getFullName(), productConfig);
    builder.outputPath(outputPath + File.separator + productConfig.getPackageName() + ".Tests.csproj");
    builder.templateFileName(UNITTEST_CSPROJ_TEMPLATE_FILENAME);
    return builder.build();
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ClientTestFileView(com.google.api.codegen.viewmodel.testing.ClientTestFileView)

Example 3 with GapicProductConfig

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

the class GoGapicSurfaceTransformer method generate.

private StaticLangClientFileView generate(GapicInterfaceContext context) {
    StaticLangClientFileView.Builder view = StaticLangClientFileView.newBuilder();
    SurfaceNamer namer = context.getNamer();
    ApiModel model = context.getApiModel();
    ProtoInterfaceModel apiInterface = context.getInterfaceModel();
    GapicProductConfig productConfig = context.getProductConfig();
    GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
    view.templateFileName(API_TEMPLATE_FILENAME);
    view.serviceDoc(serviceTransformer.generateServiceDoc(context, null, productConfig));
    view.domainLayerLocation(productConfig.getDomainLayerLocation());
    view.clientTypeName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    view.clientConstructorName(namer.getApiWrapperClassConstructorName(interfaceConfig));
    view.defaultClientOptionFunctionName(namer.getDefaultApiSettingsFunctionName(interfaceConfig));
    view.defaultCallOptionFunctionName(namer.getDefaultCallSettingsFunctionName(interfaceConfig));
    view.callOptionsTypeName(namer.getCallSettingsTypeName(interfaceConfig));
    view.serviceOriginalName(model.getTitle());
    view.servicePhraseName(namer.getServicePhraseName(interfaceConfig));
    String outputPath = pathMapper.getOutputPath(apiInterface.getFullName(), productConfig);
    String fileName = namer.getServiceFileName(context.getInterfaceConfig());
    view.outputPath(outputPath + File.separator + fileName);
    List<RetryConfigDefinitionView> retryDef = generateRetryConfigDefinitions(context, context.getSupportedMethods());
    view.retryPairDefinitions(retryDef);
    view.callSettings(apiCallableTransformer.generateCallSettings(context));
    List<StaticLangApiMethodView> apiMethods = generateApiMethods(context, context.getSupportedMethods());
    view.apiMethods(apiMethods);
    // "net/url" is needed for `url.QueryEscape`.
    if (apiMethods.stream().anyMatch(m -> !m.headerRequestParams().isEmpty())) {
        context.getImportTypeTable().saveNicknameFor("fmt;;;");
        context.getImportTypeTable().saveNicknameFor("net/url;;;");
    }
    // In Go, multiple methods share the same iterator type, one iterator type per resource type.
    // We have to dedupe the iterators.
    Map<String, PageStreamingDescriptorClassView> iterators = new TreeMap<>();
    for (PageStreamingDescriptorClassView desc : pageStreamingTransformer.generateDescriptorClasses(context)) {
        iterators.put(desc.typeName(), desc);
    }
    view.pageStreamingDescriptorClasses(new ArrayList<>(iterators.values()));
    // Same with long running operations.
    Map<String, LongRunningOperationDetailView> lros = new TreeMap<>();
    for (StaticLangApiMethodView apiMethod : apiMethods) {
        LongRunningOperationDetailView lro = apiMethod.operationMethod();
        if (lro != null) {
            lros.put(lro.clientReturnTypeName(), lro);
        }
    }
    view.lroDetailViews(new ArrayList<>(lros.values()));
    view.serviceHostname(productServiceConfig.getServiceHostname(context.getServiceAddress()));
    view.servicePort(productServiceConfig.getServicePort(context.getServiceAddress()));
    view.stubs(grpcStubTransformer.generateGrpcStubs(context));
    addXApiImports(context, context.getSupportedMethods());
    view.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    return view.build();
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) RetryConfigDefinitionView(com.google.api.codegen.viewmodel.RetryConfigDefinitionView) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) ApiModel(com.google.api.codegen.config.ApiModel) TreeMap(java.util.TreeMap) LongRunningOperationDetailView(com.google.api.codegen.viewmodel.LongRunningOperationDetailView) StaticLangClientFileView(com.google.api.codegen.viewmodel.StaticLangClientFileView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) PageStreamingDescriptorClassView(com.google.api.codegen.viewmodel.PageStreamingDescriptorClassView)

Example 4 with GapicProductConfig

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

the class CSharpGapicClientPackageTransformer method generateCsProjView.

private PackageInfoView generateCsProjView(GapicInterfaceContext context) {
    Model model = context.getModel();
    GapicProductConfig productConfig = context.getProductConfig();
    PackageInfoView.Builder view = PackageInfoView.newBuilder();
    view.templateFileName(CSPROJ_TEMPLATE_FILENAME);
    String outputPath = pathMapper.getOutputPath(context.getInterface().getFullName(), productConfig);
    view.outputPath(outputPath + File.separator + productConfig.getPackageName() + ".csproj");
    view.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    view.serviceTitle(model.getServiceConfig().getTitle());
    view.serviceDescription(model.getServiceConfig().getDocumentation().getSummary().trim());
    view.domainLayerLocation(productConfig.getDomainLayerLocation());
    // Unused in C#
    view.authScopes(new ArrayList<>());
    view.releaseLevel(productConfig.getReleaseLevel());
    String versionSuffix;
    switch(productConfig.getReleaseLevel()) {
        case ALPHA:
            versionSuffix = "-alpha01";
            break;
        case BETA:
            versionSuffix = "-beta01";
            break;
        default:
            versionSuffix = "";
            break;
    }
    view.version("1.0.0" + versionSuffix);
    String tags = "";
    for (String tag : Splitter.on('.').split(productConfig.getPackageName())) {
        if (tag.matches("[vV][\\d.]+")) {
            break;
        }
        tags += ";" + tag;
    }
    view.tags(tags.isEmpty() ? "" : tags.substring(1));
    view.packageMetadata(generatePackageMetadataView(context));
    view.serviceDocs(new ArrayList<>());
    return view.build();
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ViewModel(com.google.api.codegen.viewmodel.ViewModel) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) InterfaceModel(com.google.api.codegen.config.InterfaceModel) Model(com.google.api.tools.framework.model.Model) PackageInfoView(com.google.api.codegen.viewmodel.PackageInfoView)

Example 5 with GapicProductConfig

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

the class StaticLangGapicSamplesTransformer method generateSamplesFromGapicConfigs.

private List<ViewModel> generateSamplesFromGapicConfigs(List<InterfaceContext> interfaceContexts, GapicProductConfig productConfig, SurfaceNamer namer) {
    List<MethodSampleView> allSamples = interfaceContexts.stream().flatMap(iface -> apiMethodTransformer.generateApiMethods(iface).stream()).flatMap(method -> method.samples().stream()).collect(ImmutableList.toImmutableList());
    SampleFileRegistry registry = new SampleFileRegistry(namer, allSamples);
    List<ViewModel> sampleFileViews = new ArrayList<>();
    for (InterfaceContext context : interfaceContexts) {
        List<StaticLangApiMethodView> methods = apiMethodTransformer.generateApiMethods(context);
        for (StaticLangApiMethodView method : methods) {
            for (MethodSampleView sample : method.samples()) {
                sampleFileViews.add(newSampleFileView(productConfig, context, registry.getSampleClassName(sample, method.name()), registry.getSampleFileName(sample, method.name()), method, sample));
            }
        }
    }
    return sampleFileViews;
}
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) MethodSampleView(com.google.api.codegen.viewmodel.MethodSampleView) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceContext(com.google.api.codegen.config.InterfaceContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext)

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