Search in sources :

Example 6 with ApiMethodView

use of com.google.api.codegen.viewmodel.ApiMethodView in project toolkit by googleapis.

the class JavaSurfaceTransformer method generateApiClass.

private StaticLangApiView generateApiClass(InterfaceContext context, GapicProductConfig productConfig) {
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    addApiImports(context);
    List<StaticLangApiMethodView> methods = generateApiMethods(context);
    StaticLangApiView.Builder xapiClass = StaticLangApiView.newBuilder();
    ApiMethodView exampleApiMethod = getExampleApiMethod(methods);
    xapiClass.doc(serviceTransformer.generateServiceDoc(context, exampleApiMethod, productConfig));
    String name = context.getNamer().getApiWrapperClassName(context.getInterfaceConfig());
    xapiClass.releaseLevelAnnotation(namer.getReleaseAnnotation(packageMetadataConfig.releaseLevel(TargetLanguage.JAVA)));
    xapiClass.name(name);
    xapiClass.settingsClassName(namer.getApiSettingsClassName(interfaceConfig));
    xapiClass.stubInterfaceName(getAndSaveNicknameForStubType(context, namer.getApiStubInterfaceName(interfaceConfig)));
    xapiClass.stubSettingsClassName(getAndSaveNicknameForStubType(context, namer.getApiStubSettingsClassName(interfaceConfig)));
    xapiClass.apiCallableMembers(apiCallableTransformer.generateStaticLangApiCallables(context));
    xapiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
    xapiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
    xapiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
    xapiClass.apiMethods(methods);
    xapiClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
    xapiClass.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations());
    xapiClass.pagedResponseViews(generatePagedResponseWrappers(context, productConfig, packageMetadataConfig.releaseLevel(TargetLanguage.JAVA)));
    return xapiClass.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView)

Example 7 with ApiMethodView

use of com.google.api.codegen.viewmodel.ApiMethodView in project toolkit by googleapis.

the class NodeJSGapicSurfaceTransformer method generateApiClass.

private ViewModel generateApiClass(GapicInterfaceContext context, boolean hasMultipleServices) {
    SurfaceNamer namer = context.getNamer();
    String subPath = pathMapper.getOutputPath(context.getInterface().getFullName(), context.getProductConfig());
    List<ApiMethodView> methods = generateApiMethods(context, hasMultipleServices);
    DynamicLangXApiView.Builder xapiClass = DynamicLangXApiView.newBuilder();
    xapiClass.templateFileName(XAPI_TEMPLATE_FILENAME);
    xapiClass.outputPath(subPath + "/" + namer.getServiceFileName(context.getInterfaceConfig()));
    xapiClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    xapiClass.protoFilename(context.getInterface().getFile().getSimpleName());
    xapiClass.name(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    xapiClass.doc(serviceTransformer.generateServiceDoc(context, methods.get(0), context.getProductConfig()));
    xapiClass.stubs(grpcStubTransformer.generateGrpcStubs(context));
    ApiModel model = context.getApiModel();
    xapiClass.serviceAddress(model.getServiceAddress());
    xapiClass.servicePort(model.getServicePort());
    xapiClass.serviceTitle(model.getTitle());
    xapiClass.authScopes(model.getAuthScopes());
    xapiClass.hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress());
    xapiClass.hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes());
    xapiClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptors(context));
    xapiClass.batchingDescriptors(batchingTransformer.generateDescriptors(context));
    xapiClass.longRunningDescriptors(createLongRunningDescriptors(context));
    xapiClass.grpcStreamingDescriptors(createGrpcStreamingDescriptors(context));
    xapiClass.hasPageStreamingMethods(context.getInterfaceConfig().hasPageStreamingMethods());
    xapiClass.hasBatchingMethods(context.getInterfaceConfig().hasBatchingMethods());
    xapiClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
    xapiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
    xapiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
    xapiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
    xapiClass.pathTemplateGetterFunctions(ImmutableList.<PathTemplateGetterFunctionView>of());
    xapiClass.methodKeys(ImmutableList.<String>of());
    xapiClass.interfaceKey(context.getInterface().getFullName());
    xapiClass.clientConfigPath(namer.getClientConfigPath(context.getInterfaceConfig()));
    xapiClass.grpcClientTypeName(namer.getAndSaveNicknameForGrpcClientTypeName(context.getImportTypeTable(), context.getInterfaceModel()));
    xapiClass.apiMethods(methods);
    xapiClass.toolkitVersion(GeneratorVersionProvider.getGeneratorVersion());
    xapiClass.packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.NODEJS).lower());
    xapiClass.apiVersion(packageConfig.apiVersion());
    xapiClass.packageHasMultipleServices(hasMultipleServices);
    xapiClass.packageServiceName(namer.getPackageServiceName(context.getInterfaceConfig()));
    xapiClass.validDescriptorsNames(generateValidDescriptorsNames(context));
    xapiClass.constructorName(namer.getApiWrapperClassConstructorName(context.getInterfaceConfig()));
    xapiClass.isGcloud(NodeJSUtils.isGcloud(context.getProductConfig()));
    return xapiClass.build();
}
Also used : ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) DynamicLangXApiView(com.google.api.codegen.viewmodel.DynamicLangXApiView) ApiModel(com.google.api.codegen.config.ApiModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 8 with ApiMethodView

use of com.google.api.codegen.viewmodel.ApiMethodView in project toolkit by googleapis.

the class RubyGapicSurfaceTransformer method generateApiClass.

private ViewModel generateApiClass(GapicInterfaceContext context, String packageName) {
    SurfaceNamer namer = context.getNamer();
    PackageMetadataNamer metadataNamer = new RubyPackageMetadataNamer(packageName);
    String subPath = pathMapper.getOutputPath(context.getInterface().getFullName(), context.getProductConfig());
    String name = namer.getApiWrapperClassName(context.getInterfaceConfig());
    List<ApiMethodView> methods = generateApiMethods(context);
    DynamicLangXApiView.Builder xapiClass = DynamicLangXApiView.newBuilder();
    xapiClass.templateFileName(XAPI_TEMPLATE_FILENAME);
    xapiClass.outputPath(namer.getSourceFilePath(subPath, name));
    xapiClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    xapiClass.protoFilename(context.getInterface().getFile().getSimpleName());
    xapiClass.name(name);
    xapiClass.doc(serviceTransformer.generateServiceDoc(context, methods.get(0), context.getProductConfig()));
    xapiClass.stubs(grpcStubTransformer.generateGrpcStubs(context));
    ApiModel model = context.getApiModel();
    xapiClass.serviceAddress(model.getServiceAddress());
    xapiClass.servicePort(model.getServicePort());
    xapiClass.serviceTitle(model.getTitle());
    xapiClass.authScopes(model.getAuthScopes());
    xapiClass.hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress());
    xapiClass.hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes());
    xapiClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptors(context));
    xapiClass.batchingDescriptors(batchingTransformer.generateDescriptors(context));
    xapiClass.longRunningDescriptors(ImmutableList.<LongRunningOperationDetailView>of());
    xapiClass.grpcStreamingDescriptors(ImmutableList.<GrpcStreamingDetailView>of());
    xapiClass.hasPageStreamingMethods(context.getInterfaceConfig().hasPageStreamingMethods());
    xapiClass.hasBatchingMethods(context.getInterfaceConfig().hasBatchingMethods());
    xapiClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
    xapiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
    xapiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
    xapiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
    xapiClass.pathTemplateGetterFunctions(ImmutableList.<PathTemplateGetterFunctionView>of());
    xapiClass.methodKeys(ImmutableList.<String>of());
    xapiClass.interfaceKey(context.getInterface().getFullName());
    xapiClass.clientConfigPath(namer.getClientConfigPath(context.getInterfaceConfig()));
    xapiClass.grpcClientTypeName(namer.getAndSaveNicknameForGrpcClientTypeName(context.getImportTypeTable(), context.getInterfaceModel()));
    xapiClass.apiMethods(methods);
    xapiClass.toolkitVersion(GeneratorVersionProvider.getGeneratorVersion());
    xapiClass.gapicPackageName(RubyUtil.isLongrunning(context.getProductConfig().getPackageName()) ? "google-gax" : metadataNamer.getMetadataIdentifier());
    xapiClass.fullyQualifiedCredentialsClassName(namer.getFullyQualifiedCredentialsClassName());
    xapiClass.defaultCredentialsInitializerCall(RubyUtil.isLongrunning(context.getProductConfig().getPackageName()) ? "default(scopes: scopes)" : "default");
    return xapiClass.build();
}
Also used : ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) DynamicLangXApiView(com.google.api.codegen.viewmodel.DynamicLangXApiView) ApiModel(com.google.api.codegen.config.ApiModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) PackageMetadataNamer(com.google.api.codegen.transformer.PackageMetadataNamer)

Example 9 with ApiMethodView

use of com.google.api.codegen.viewmodel.ApiMethodView in project toolkit by googleapis.

the class RubyPackageMetadataTransformer 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, model.hasMultipleServices()));
        }
    }
    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)

Aggregations

ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)9 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)5 InterfaceModel (com.google.api.codegen.config.InterfaceModel)4 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)4 DynamicLangXApiView (com.google.api.codegen.viewmodel.DynamicLangXApiView)4 ApiModel (com.google.api.codegen.config.ApiModel)3 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)3 MethodModel (com.google.api.codegen.config.MethodModel)3 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)3 ImmutableList (com.google.common.collect.ImmutableList)3 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)1 ProductServiceConfig (com.google.api.codegen.config.ProductServiceConfig)1 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)1 PackageMetadataNamer (com.google.api.codegen.transformer.PackageMetadataNamer)1 Name (com.google.api.codegen.util.Name)1 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)1 StaticLangApiView (com.google.api.codegen.viewmodel.StaticLangApiView)1 ViewModel (com.google.api.codegen.viewmodel.ViewModel)1 VersionIndexRequireView (com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)1 VersionIndexView (com.google.api.codegen.viewmodel.metadata.VersionIndexView)1