Search in sources :

Example 61 with SurfaceNamer

use of com.google.api.codegen.transformer.SurfaceNamer 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 62 with SurfaceNamer

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

the class PythonGapicSurfaceTransformer method generateVersionedInitView.

private ViewModel generateVersionedInitView(Model model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
    boolean packageHasEnums = packageHasEnums(model);
    ImportSectionView imports = importSectionTransformer.generateVersionedInitImportSection(model, productConfig, namer, packageHasEnums);
    return VersionIndexView.newBuilder().templateFileName(VERSIONED_INIT_TEMPLATE_FILENAME).outputPath(versionedInitOutputFile(namer)).requireViews(versionedInitRequireViews(model, productConfig, namer)).apiVersion(namer.getApiWrapperModuleVersion()).namespace(namer.getVersionedDirectoryNamespace()).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.PYTHON).lower()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, imports, namer)).packageHasEnums(packageHasEnums).build();
}
Also used : SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 63 with SurfaceNamer

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

the class PythonGapicSurfaceTransformer method generateServiceSurfaces.

private Iterable<ViewModel> generateServiceSurfaces(Model model, GapicProductConfig productConfig) {
    ModelTypeTable modelTypeTable = new ModelTypeTable(new PythonTypeTable(productConfig.getPackageName()), new PythonModelTypeNameConverter(productConfig.getPackageName()));
    SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
    FeatureConfig featureConfig = new DefaultFeatureConfig();
    ProtoApiModel apiModel = new ProtoApiModel(model);
    ImmutableList.Builder<ViewModel> serviceSurfaces = ImmutableList.builder();
    for (InterfaceModel apiInterface : apiModel.getInterfaces()) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, modelTypeTable, namer, featureConfig);
        addApiImports(context);
        serviceSurfaces.add(generateApiClass(context));
    }
    GrpcDocView enumFile = generateEnumView(productConfig, modelTypeTable, namer, model.getFiles());
    if (!enumFile.elementDocs().isEmpty()) {
        serviceSurfaces.add(enumFile);
    }
    return serviceSurfaces.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FeatureConfig(com.google.api.codegen.transformer.FeatureConfig) DefaultFeatureConfig(com.google.api.codegen.transformer.DefaultFeatureConfig) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) GrpcDocView(com.google.api.codegen.viewmodel.GrpcDocView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) PythonTypeTable(com.google.api.codegen.util.py.PythonTypeTable) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) DefaultFeatureConfig(com.google.api.codegen.transformer.DefaultFeatureConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 64 with SurfaceNamer

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

the class RubyGapicSurfaceDocTransformer method generateOverview.

private ViewModel generateOverview(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    GrpcDocView.Builder doc = GrpcDocView.newBuilder();
    doc.templateFileName(DOC_TEMPLATE_FILENAME);
    doc.outputPath(pathMapper.getOutputPath(null, productConfig) + "/doc/overview.rb");
    doc.fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer));
    doc.elementDocs(ImmutableList.<GrpcElementDocView>of());
    doc.modules(generateModuleViews(model, productConfig, namer, null, true));
    return doc.build();
}
Also used : GrpcDocView(com.google.api.codegen.viewmodel.GrpcDocView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 65 with SurfaceNamer

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

the class DiscoGapicGeneratorApi method getProviders.

/**
 * From config file paths, constructs the DiscoGapicProviders to run.
 */
@VisibleForTesting
static List<GapicProvider> getProviders(String discoveryDocPath, List<String> configFileNames, String packageConfigFile, List<String> enabledArtifacts) throws IOException {
    if (!new File(discoveryDocPath).exists()) {
        throw new IOException("File not found: " + discoveryDocPath);
    }
    Reader reader = new InputStreamReader(new FileInputStream(new File(discoveryDocPath)));
    ObjectMapper mapper = new ObjectMapper();
    JsonNode root = mapper.readTree(reader);
    // Read the YAML config and convert it to proto.
    if (configFileNames.size() == 0) {
        throw new IOException(String.format("--%s must be provided", GENERATOR_CONFIG_FILES.name()));
    }
    ConfigProto configProto = loadConfigFromFiles(configFileNames);
    if (configProto == null) {
        throw new IOException("Failed to load config proto.");
    }
    PackageMetadataConfig packageConfig = null;
    if (!Strings.isNullOrEmpty(packageConfigFile)) {
        String contents = new String(Files.readAllBytes(Paths.get(packageConfigFile)), StandardCharsets.UTF_8);
        packageConfig = PackageMetadataConfig.createFromString(contents);
    }
    GeneratorProto generator = configProto.getGenerator();
    String language = configProto.getLanguage();
    String defaultPackageName = configProto.getLanguageSettingsMap().get(language).getPackageName();
    SurfaceNamer surfaceNamer = null;
    if (language.equals(JAVA)) {
        surfaceNamer = new JavaSurfaceNamer(defaultPackageName, defaultPackageName, new JavaNameFormatter());
    }
    if (surfaceNamer == null) {
        throw new UnsupportedOperationException("DiscoGapicGeneratorApi: language \"" + language + "\" not yet supported");
    }
    DiscoApiModel model = new DiscoApiModel(Document.from(new DiscoveryNode(root)), defaultPackageName);
    GapicProductConfig productConfig = GapicProductConfig.create(model, configProto, surfaceNamer);
    String factory = generator.getFactory();
    String id = generator.getId();
    DiscoGapicProviderFactory providerFactory = createProviderFactory(factory);
    GapicGeneratorConfig generatorConfig = GapicGeneratorConfig.newBuilder().id(id).enabledArtifacts(enabledArtifacts).build();
    return providerFactory.create(model, productConfig, generatorConfig, packageConfig);
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) DiscoveryNode(com.google.api.codegen.discovery.DiscoveryNode) InputStreamReader(java.io.InputStreamReader) ConfigYamlReader(com.google.api.codegen.configgen.ConfigYamlReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) FileInputStream(java.io.FileInputStream) JavaNameFormatter(com.google.api.codegen.util.java.JavaNameFormatter) DiscoGapicProviderFactory(com.google.api.codegen.discogapic.DiscoGapicProviderFactory) DiscoApiModel(com.google.api.codegen.config.DiscoApiModel) GapicGeneratorConfig(com.google.api.codegen.gapic.GapicGeneratorConfig) PackageMetadataConfig(com.google.api.codegen.config.PackageMetadataConfig) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JavaSurfaceNamer(com.google.api.codegen.transformer.java.JavaSurfaceNamer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)109 InterfaceModel (com.google.api.codegen.config.InterfaceModel)26 ViewModel (com.google.api.codegen.viewmodel.ViewModel)23 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)22 ArrayList (java.util.ArrayList)22 ImmutableList (com.google.common.collect.ImmutableList)17 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)15 MethodModel (com.google.api.codegen.config.MethodModel)14 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)13 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)11 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)10 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)10 FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)10 ApiModel (com.google.api.codegen.config.ApiModel)9 MethodConfig (com.google.api.codegen.config.MethodConfig)9 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)9 DynamicLangXApiView (com.google.api.codegen.viewmodel.DynamicLangXApiView)9 FieldConfig (com.google.api.codegen.config.FieldConfig)8 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)8 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)8