Search in sources :

Example 11 with GapicInterfaceContext

use of com.google.api.codegen.transformer.GapicInterfaceContext in project toolkit by googleapis.

the class PythonPackageMetadataTransformer method generateExampleMethods.

// Generates methods used as examples for the README.md file.
// This currently generates a list of methods that have smoke test configuration. In the future,
// the example methods may be configured separately.
private List<ApiMethodView> generateExampleMethods(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ApiMethodView> exampleMethods = ImmutableList.builder();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
            FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
            GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
            exampleMethods.add(createExampleApiMethodView(flattenedMethodContext));
        }
    }
    return exampleMethods.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 12 with GapicInterfaceContext

use of com.google.api.codegen.transformer.GapicInterfaceContext in project toolkit by googleapis.

the class RubyGapicSurfaceTransformer method generateVersionIndexView.

private ViewModel generateVersionIndexView(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    ImmutableList.Builder<VersionIndexRequireView> requireViews = ImmutableList.builder();
    Iterable<? extends InterfaceModel> interfaces = model.getInterfaces();
    for (InterfaceModel apiInterface : interfaces) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        requireViews.add(VersionIndexRequireView.newBuilder().clientName(namer.getFullyQualifiedApiWrapperClassName(interfaceConfig)).fileName(namer.getServiceFileName(interfaceConfig)).serviceName(namer.getPackageServiceName(context.getInterfaceConfig())).doc(serviceTransformer.generateServiceDoc(context, generateApiMethods(context).get(0), productConfig)).build());
    }
    // append any additional types
    Set<String> requireTypes = new HashSet<>();
    for (TypeModel type : model.getAdditionalTypes()) {
        if (type instanceof ProtoTypeRef) {
            ProtoTypeRef t = (ProtoTypeRef) type;
            String name = namer.getVersionIndexFileImportName() + "/" + namer.getProtoFileImportName(t.getProtoType().getMessageType().getFile().getSimpleName());
            requireTypes.add(name);
        }
    }
    return VersionIndexView.newBuilder().apiVersion(packageConfig.apiVersion()).requireViews(requireViews.build()).requireTypes(ImmutableList.copyOf(requireTypes)).templateFileName(VERSION_INDEX_TEMPLATE_FILE).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.RUBY).lower()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).outputPath("lib" + File.separator + versionPackagePath(namer) + ".rb").modules(generateModuleViews(model, productConfig, true)).type(VersionIndexType.VersionIndex).toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()).build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ProtoTypeRef(com.google.api.codegen.config.ProtoTypeRef) TypeModel(com.google.api.codegen.config.TypeModel) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) InterfaceModel(com.google.api.codegen.config.InterfaceModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) HashSet(java.util.HashSet)

Example 13 with GapicInterfaceContext

use of com.google.api.codegen.transformer.GapicInterfaceContext in project toolkit by googleapis.

the class RubyImportSectionTransformer method generateRakefileAcceptanceTaskImportSection.

public ImportSectionView generateRakefileAcceptanceTaskImportSection(List<GapicInterfaceContext> contexts) {
    List<ImportFileView> none = ImmutableList.of();
    ImportSectionView.Builder importSection = ImportSectionView.newBuilder();
    importSection.standardImports(none);
    importSection.externalImports(none);
    Set<ImportFileView> credentialsImports = new HashSet<>();
    for (GapicInterfaceContext context : contexts) {
        credentialsImports.add(createImport(context.getNamer().getCredentialsClassImportName()));
    }
    importSection.appImports(ImmutableList.copyOf(credentialsImports));
    importSection.serviceImports(none);
    return importSection.build();
}
Also used : ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView) HashSet(java.util.HashSet)

Example 14 with GapicInterfaceContext

use of com.google.api.codegen.transformer.GapicInterfaceContext in project toolkit by googleapis.

the class CSharpGapicClientTransformer method generateApiClass.

private StaticLangApiView generateApiClass(GapicInterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    StaticLangApiView.Builder apiClass = StaticLangApiView.newBuilder();
    List<StaticLangApiMethodView> methods = generateApiMethods(context);
    apiClass.doc(serviceTransformer.generateServiceDoc(context, null, context.getProductConfig()));
    apiClass.name(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    apiClass.implName(namer.getApiWrapperClassImplName(context.getInterfaceConfig()));
    apiClass.grpcServiceName(namer.getGrpcContainerTypeName(context.getInterfaceModel()));
    String grpcTypeName = namer.getGrpcServiceClassName(context.getInterfaceModel());
    int dotIndex = grpcTypeName.indexOf('.');
    apiClass.grpcTypeNameOuter(grpcTypeName.substring(0, dotIndex));
    apiClass.grpcTypeNameInner(grpcTypeName.substring(dotIndex + 1, grpcTypeName.length()));
    apiClass.settingsClassName(context.getNamer().getApiSettingsClassName(context.getInterfaceConfig()));
    List<ApiCallableView> callables = new ArrayList<>();
    for (ApiCallableView call : apiCallableTransformer.generateStaticLangApiCallables(context)) {
        if (call.type() == ApiCallableImplType.SimpleApiCallable || call.type() == ApiCallableImplType.BatchingApiCallable || call.type() == ApiCallableImplType.BidiStreamingApiCallable || call.type() == ApiCallableImplType.ServerStreamingApiCallable) {
            callables.add(call);
        }
    }
    apiClass.apiCallableMembers(callables);
    apiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
    apiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
    apiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
    apiClass.apiMethods(methods);
    List<StaticLangApiMethodView> methodsImpl = new ArrayList<>();
    for (StaticLangApiMethodView method : methods) {
        if (methodTypeHasImpl(method.type())) {
            methodsImpl.add(method);
        }
    }
    apiClass.apiMethodsImpl(methodsImpl);
    apiClass.hasDefaultInstance(context.getInterfaceConfig().hasDefaultInstance());
    apiClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
    apiClass.reroutedGrpcClients(csharpCommonTransformer.generateReroutedGrpcView(context));
    apiClass.modifyMethods(generateModifyMethods(context));
    apiClass.apiHasUnaryMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.NonStreaming));
    apiClass.apiHasServerStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.ServerStreaming));
    apiClass.apiHasClientStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.ClientStreaming));
    apiClass.apiHasBidiStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.BidiStreaming));
    return apiClass.build();
}
Also used : TargetLanguage(com.google.api.codegen.TargetLanguage) Arrays(java.util.Arrays) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) ApiCallableView(com.google.api.codegen.viewmodel.ApiCallableView) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) StaticLangApiMethodTransformer(com.google.api.codegen.transformer.StaticLangApiMethodTransformer) MethodContext(com.google.api.codegen.transformer.MethodContext) BatchingTransformer(com.google.api.codegen.transformer.BatchingTransformer) ViewModel(com.google.api.codegen.viewmodel.ViewModel) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) ApiCallSettingsView(com.google.api.codegen.viewmodel.ApiCallSettingsView) Splitter(com.google.common.base.Splitter) CSharpTypeTable(com.google.api.codegen.util.csharp.CSharpTypeTable) GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) PackageMetadataTransformer(com.google.api.codegen.transformer.PackageMetadataTransformer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) Set(java.util.Set) FileHeaderTransformer(com.google.api.codegen.transformer.FileHeaderTransformer) PackageInfoView(com.google.api.codegen.viewmodel.PackageInfoView) List(java.util.List) ApiCallableTransformer(com.google.api.codegen.transformer.ApiCallableTransformer) InterfaceModel(com.google.api.codegen.config.InterfaceModel) SettingsDocView(com.google.api.codegen.viewmodel.SettingsDocView) ModelToViewTransformer(com.google.api.codegen.transformer.ModelToViewTransformer) ApiCallableImplType(com.google.api.codegen.viewmodel.ApiCallableImplType) StandardImportSectionTransformer(com.google.api.codegen.transformer.StandardImportSectionTransformer) PackageMetadataView(com.google.api.codegen.viewmodel.metadata.PackageMetadataView) PackageMetadataConfig(com.google.api.codegen.config.PackageMetadataConfig) GrpcStreamingType(com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType) PageStreamingTransformer(com.google.api.codegen.transformer.PageStreamingTransformer) ServiceTransformer(com.google.api.codegen.transformer.ServiceTransformer) PathTemplateTransformer(com.google.api.codegen.transformer.PathTemplateTransformer) StaticLangApiAndSettingsFileView(com.google.api.codegen.viewmodel.StaticLangApiAndSettingsFileView) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) PackageMetadataNamer(com.google.api.codegen.transformer.PackageMetadataNamer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) MethodModel(com.google.api.codegen.config.MethodModel) ParamWithSimpleDoc(com.google.api.codegen.transformer.ParamWithSimpleDoc) MethodConfig(com.google.api.codegen.config.MethodConfig) StaticLangSettingsView(com.google.api.codegen.viewmodel.StaticLangSettingsView) File(java.io.File) StaticLangResourceNamesView(com.google.api.codegen.viewmodel.StaticLangResourceNamesView) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ApiModel(com.google.api.codegen.config.ApiModel) ServiceDocView(com.google.api.codegen.viewmodel.ServiceDocView) RetryDefinitionsTransformer(com.google.api.codegen.transformer.RetryDefinitionsTransformer) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) Model(com.google.api.tools.framework.model.Model) ModifyMethodView(com.google.api.codegen.viewmodel.ModifyMethodView) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) ApiCallableView(com.google.api.codegen.viewmodel.ApiCallableView) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ArrayList(java.util.ArrayList) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView)

Example 15 with GapicInterfaceContext

use of com.google.api.codegen.transformer.GapicInterfaceContext in project toolkit by googleapis.

the class CSharpGapicClientTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName());
    CSharpFeatureConfig featureConfig = new CSharpFeatureConfig();
    InterfaceModel lastApiInterface = null;
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(productConfig.getPackageName()), namer, featureConfig);
        surfaceDocs.add(generateApiAndSettingsView(context));
        lastApiInterface = apiInterface;
    }
    GapicInterfaceContext context = GapicInterfaceContext.create(lastApiInterface, productConfig, createTypeTable(productConfig.getPackageName()), namer, featureConfig);
    surfaceDocs.add(generateResourceNamesView(context));
    surfaceDocs.add(generateCsProjView(context));
    return surfaceDocs;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)27 InterfaceModel (com.google.api.codegen.config.InterfaceModel)24 ViewModel (com.google.api.codegen.viewmodel.ViewModel)16 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)13 ArrayList (java.util.ArrayList)13 ImmutableList (com.google.common.collect.ImmutableList)12 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)9 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)7 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)4 MethodModel (com.google.api.codegen.config.MethodModel)4 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)4 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)3 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)3 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)2 FeatureConfig (com.google.api.codegen.transformer.FeatureConfig)2 VersionIndexRequireView (com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)2 MockServiceImplView (com.google.api.codegen.viewmodel.testing.MockServiceImplView)2 HashSet (java.util.HashSet)2 TargetLanguage (com.google.api.codegen.TargetLanguage)1 ApiModel (com.google.api.codegen.config.ApiModel)1