Search in sources :

Example 51 with SurfaceNamer

use of com.google.api.codegen.transformer.SurfaceNamer 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(productConfig);
    for (InterfaceModel apiInterface : interfaces) {
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        if (interfaceConfig == null) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        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.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).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).outputPath("lib" + File.separator + versionPackagePath(namer) + ".rb").modules(generateModuleViews(model, productConfig, true)).type(VersionIndexType.VersionIndex).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.config.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 52 with SurfaceNamer

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

the class RubyGapicSurfaceTransformer method generateCredentialsClass.

private CredentialsClassView generateCredentialsClass(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    String sanitizedShortName = packageConfig.shortName().replaceAll("[^A-Za-z0-9]", " ");
    Name.lowerCamel(sanitizedShortName.split(" "));
    List<String> apiSpecificPathEnvVars = ImmutableList.of(namer.inittedConstantName(Name.lowerCamel(sanitizedShortName.split(" ")).join("credentials")), namer.inittedConstantName(Name.lowerCamel(sanitizedShortName.split(" ")).join("keyfile")));
    List<String> apiSpecificJsonEnvVars = ImmutableList.of(namer.inittedConstantName(Name.lowerCamel(sanitizedShortName.split(" ")).join("credentials").join("json")), namer.inittedConstantName(Name.lowerCamel(sanitizedShortName.split(" ")).join("keyfile").join("json")));
    List<String> pathEnvVars = ImmutableList.<String>builder().addAll(apiSpecificPathEnvVars).addAll(DEFAULT_PATH_ENV_VARS).build();
    List<String> jsonEnvVars = ImmutableList.<String>builder().addAll(apiSpecificJsonEnvVars).addAll(DEFAULT_JSON_ENV_VARS).build();
    return CredentialsClassView.newBuilder().pathEnvVars(pathEnvVars).jsonEnvVars(jsonEnvVars).defaultPaths(DEFAULT_PATHS).scopes(model.getAuthScopes(productConfig)).build();
}
Also used : SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 53 with SurfaceNamer

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

the class PythonPackageMetadataTransformer method generateNoxFile.

private ViewModel generateNoxFile(ApiModel model, GapicProductConfig productConfig) {
    PackageMetadataNamer namer = new PackageMetadataNamer();
    SurfaceNamer surfaceNamer = new PythonSurfaceNamer(productConfig.getPackageName());
    String outputPath = "noxfile.py";
    return generateMetadataView(model, productConfig, NOX_TEMPLATE_FILE, namer, surfaceNamer, outputPath).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSectionTransformer.generateNoxImportSection(), new PythonSurfaceNamer(productConfig.getPackageName()))).build();
}
Also used : PackageMetadataNamer(com.google.api.codegen.transformer.PackageMetadataNamer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 54 with SurfaceNamer

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

the class PythonPackageMetadataTransformer method generateDocFiles.

private List<ViewModel> generateDocFiles(ApiModel model, GapicProductConfig productConfig) {
    PackageMetadataNamer namer = new PackageMetadataNamer();
    SurfaceNamer surfaceNamer = new PythonSurfaceNamer(productConfig.getPackageName());
    String docsGapicPath = docsGapicPath(packageConfig.apiVersion());
    String typesOutputPath = String.format("docs/%s/types.rst", docsGapicPath);
    String apiOutputPath = String.format("docs/%s/api.rst", docsGapicPath);
    return ImmutableList.<ViewModel>builder().add(generateMetadataView(model, productConfig, TYPES_DOC_TEMPLATE_FILE, namer, surfaceNamer, typesOutputPath).build()).add(generateMetadataView(model, productConfig, API_DOC_TEMPLATE_FILE, namer, surfaceNamer, apiOutputPath).build()).build();
}
Also used : PackageMetadataNamer(com.google.api.codegen.transformer.PackageMetadataNamer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 55 with SurfaceNamer

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

the class NodeJSGapicSurfaceDocTransformer method generateDoc.

private ViewModel generateDoc(ProtoFile file, GapicProductConfig productConfig) {
    ModelTypeTable typeTable = new ModelTypeTable(new JSTypeTable(productConfig.getPackageName()), new NodeJSModelTypeNameConverter(productConfig.getPackageName()));
    // Use file path for package name to get file-specific package instead of package for the API.
    SurfaceNamer namer = new NodeJSSurfaceNamer(productConfig.getPackageName(), NodeJSUtils.isGcloud(productConfig));
    JSCommentReformatter commentReformatter = new JSCommentReformatter();
    GrpcDocView.Builder doc = GrpcDocView.newBuilder();
    doc.templateFileName(DOC_TEMPLATE_FILENAME);
    doc.outputPath(getOutputPath(namer, file));
    doc.fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer));
    doc.elementDocs(grpcElementDocTransformer.generateElementDocs(productConfig, typeTable, namer, file));
    return doc.build();
}
Also used : JSTypeTable(com.google.api.codegen.util.js.JSTypeTable) JSCommentReformatter(com.google.api.codegen.util.js.JSCommentReformatter) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GrpcDocView(com.google.api.codegen.viewmodel.GrpcDocView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

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