Search in sources :

Example 11 with InterfaceConfig

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

the class JavaSurfaceTransformer method generateCallableFactoryClass.

private StaticLangCallableFactoryView generateCallableFactoryClass(InterfaceContext context, GapicProductConfig productConfig) {
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    addCallableFactoryImports(context);
    StaticLangCallableFactoryView.Builder callableFactory = StaticLangCallableFactoryView.newBuilder();
    callableFactory.doc(serviceTransformer.generateServiceDoc(context, null, productConfig));
    callableFactory.releaseLevelAnnotation(namer.getReleaseAnnotation(ReleaseLevel.BETA));
    callableFactory.name(namer.getCallableFactoryClassName(interfaceConfig, productConfig.getTransportProtocol()));
    return callableFactory.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) StaticLangCallableFactoryView(com.google.api.codegen.viewmodel.StaticLangCallableFactoryView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 12 with InterfaceConfig

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

the class JavaSurfaceTransformer method generateRpcStubClass.

private StaticLangRpcStubView generateRpcStubClass(InterfaceContext context, GapicProductConfig productConfig) {
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    addRpcStubImports(context);
    // Stub class has different default package name from method, request, and resource classes.
    InterfaceContext apiMethodsContext = context.withNewTypeTable(context.getNamer().getRootPackageName());
    List<StaticLangApiMethodView> methods = generateApiMethods(apiMethodsContext);
    StaticLangRpcStubView.Builder stubClass = StaticLangRpcStubView.newBuilder();
    stubClass.doc(serviceTransformer.generateServiceDoc(context, null, productConfig));
    String name = namer.getApiRpcStubClassName(interfaceConfig.getInterfaceModel(), productConfig.getTransportProtocol());
    stubClass.releaseLevelAnnotation(namer.getReleaseAnnotation(ReleaseLevel.BETA));
    stubClass.name(name);
    stubClass.parentName(namer.getApiStubInterfaceName(interfaceConfig));
    stubClass.settingsClassName(getAndSaveNicknameForRootType(apiMethodsContext, namer.getApiSettingsClassName(interfaceConfig)));
    stubClass.stubSettingsClassName(getAndSaveNicknameForStubType(apiMethodsContext, namer.getApiStubSettingsClassName(interfaceConfig)));
    stubClass.callableFactoryClassName(getAndSaveNicknameForStubType(apiMethodsContext, namer.getCallableFactoryClassName(interfaceConfig, productConfig.getTransportProtocol())));
    stubClass.methodDescriptors(apiCallableTransformer.generateMethodDescriptors(apiMethodsContext));
    stubClass.apiCallables(apiCallableTransformer.generateStaticLangApiCallables(apiMethodsContext));
    stubClass.callableMethods(filterIncludeCallableMethods(methods));
    stubClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
    stubClass.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations());
    for (TypeAlias alias : apiMethodsContext.getImportTypeTable().getTypeTable().getAllImports().values()) {
        context.getImportTypeTable().getAndSaveNicknameFor(alias);
    }
    return stubClass.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) TypeAlias(com.google.api.codegen.util.TypeAlias) InterfaceContext(com.google.api.codegen.transformer.InterfaceContext) StaticLangRpcStubView(com.google.api.codegen.viewmodel.StaticLangRpcStubView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 13 with InterfaceConfig

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

the class JavaSurfaceTransformer method generateStubSettingsClass.

private StaticLangStubSettingsView generateStubSettingsClass(InterfaceContext context, GapicProductConfig productConfig, StaticLangApiMethodView exampleApiMethod) {
    addSettingsImports(context);
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    ApiModel model = context.getApiModel();
    StaticLangStubSettingsView.Builder xsettingsClass = StaticLangStubSettingsView.newBuilder();
    xsettingsClass.releaseLevelAnnotation(context.getNamer().getReleaseAnnotation(packageMetadataConfig.releaseLevel(TargetLanguage.JAVA)));
    xsettingsClass.doc(generateSettingsDoc(context, exampleApiMethod, productConfig, context.getNamer().getApiStubSettingsClassName(interfaceConfig), namer.getApiStubInterfaceName(context.getInterfaceConfig())));
    String name = namer.getApiStubSettingsClassName(context.getInterfaceConfig());
    xsettingsClass.name(name);
    xsettingsClass.serviceAddress(model.getServiceAddress());
    xsettingsClass.servicePort(model.getServicePort());
    xsettingsClass.authScopes(model.getAuthScopes());
    if (productConfig.getTransportProtocol().equals(TransportProtocol.HTTP)) {
        xsettingsClass.useDefaultServicePortInEndpoint(false);
    }
    xsettingsClass.transportProtocol(productConfig.getTransportProtocol());
    xsettingsClass.rpcTransportName(namer.getTransportClassName(productConfig.getTransportProtocol()));
    xsettingsClass.transportNameGetter(namer.getTransporNameGetMethod(productConfig.getTransportProtocol()));
    xsettingsClass.defaultTransportProviderBuilder(namer.getDefaultTransportProviderBuilder(productConfig.getTransportProtocol()));
    xsettingsClass.transportProvider(namer.getTransportProvider(productConfig.getTransportProtocol()));
    xsettingsClass.instantiatingChannelProvider(namer.getInstantiatingChannelProvider(productConfig.getTransportProtocol()));
    List<ApiCallSettingsView> apiCallSettings = apiCallableTransformer.generateCallSettings(context);
    xsettingsClass.callSettings(apiCallSettings);
    xsettingsClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptorClasses(context));
    xsettingsClass.pagedListResponseFactories(pageStreamingTransformer.generateFactoryClasses(context));
    xsettingsClass.batchingDescriptors(batchingTransformer.generateDescriptorClasses(context));
    xsettingsClass.retryCodesDefinitions(retryDefinitionsTransformer.generateRetryCodesDefinitions(context));
    xsettingsClass.retryParamsDefinitions(retryDefinitionsTransformer.generateRetryParamsDefinitions(context));
    xsettingsClass.transportProtocol(productConfig.getTransportProtocol());
    xsettingsClass.hasDefaultServiceAddress(interfaceConfig.hasDefaultServiceAddress());
    xsettingsClass.hasDefaultServiceScopes(interfaceConfig.hasDefaultServiceScopes());
    xsettingsClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
    xsettingsClass.stubInterfaceName(getAndSaveNicknameForStubType(context, namer.getApiStubInterfaceName(interfaceConfig)));
    xsettingsClass.rpcStubClassName(getAndSaveNicknameForStubType(context, namer.getApiRpcStubClassName(interfaceConfig.getInterfaceModel(), productConfig.getTransportProtocol())));
    return xsettingsClass.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ApiModel(com.google.api.codegen.config.ApiModel) StaticLangStubSettingsView(com.google.api.codegen.viewmodel.StaticLangStubSettingsView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ApiCallSettingsView(com.google.api.codegen.viewmodel.ApiCallSettingsView)

Example 14 with InterfaceConfig

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

the class NodeJSImportSectionTransformer method generateExternalImports.

private List<ImportFileView> generateExternalImports(InterfaceContext context) {
    ImmutableList.Builder<ImportFileView> imports = ImmutableList.builder();
    InterfaceModel apiInterface = context.getInterfaceModel();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    String configModule = context.getNamer().getClientConfigPath(interfaceConfig);
    imports.add(createImport("gapicConfig", "./" + configModule));
    imports.add(createImport("gax", "google-gax"));
    imports.add(createImport("merge", "lodash.merge"));
    imports.add(createImport("path", "path"));
    if (context.getInterfaceConfig().hasLongRunningOperations() || context.getInterfaceConfig().hasBatchingMethods()) {
        imports.add(createImport("protobuf", "protobufjs"));
    }
    return imports.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList)

Example 15 with InterfaceConfig

use of com.google.api.codegen.config.InterfaceConfig 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)

Aggregations

InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)23 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)7 ImmutableList (com.google.common.collect.ImmutableList)5 InterfaceModel (com.google.api.codegen.config.InterfaceModel)4 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)4 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)3 MethodConfig (com.google.api.codegen.config.MethodConfig)3 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)3 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)3 Interface (com.google.api.tools.framework.model.Interface)3 ArrayList (java.util.ArrayList)3 ApiModel (com.google.api.codegen.config.ApiModel)2 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)2 ProtoInterfaceModel (com.google.api.codegen.config.ProtoInterfaceModel)2 InterfaceContext (com.google.api.codegen.transformer.InterfaceContext)2 TypeAlias (com.google.api.codegen.util.TypeAlias)2 StaticLangSettingsView (com.google.api.codegen.viewmodel.StaticLangSettingsView)2 HashSet (java.util.HashSet)2 InterfaceView (com.google.api.codegen.InterfaceView)1 ServiceMessages (com.google.api.codegen.ServiceMessages)1