Search in sources :

Example 11 with GapicInterfaceContext

use of com.google.api.codegen.config.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(productConfig)) {
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        if (interfaceConfig == null || interfaceConfig.getSmokeTestConfig() == null) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        MethodModel method = interfaceConfig.getSmokeTestConfig().getMethod();
        GapicMethodContext methodContext = context.asRequestMethodContext(method);
        FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
        GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(methodContext, flatteningGroup);
        exampleMethods.add(createExampleApiMethodView(flattenedMethodContext));
    }
    return exampleMethods.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.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.config.GapicInterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 12 with GapicInterfaceContext

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

the class NodeJSGapicSurfaceTransformer method generateIndexViews.

private List<ViewModel> generateIndexViews(Iterable<? extends InterfaceModel> apiInterfaces, GapicProductConfig productConfig) {
    NodeJSPackageMetadataNamer packageMetadataNamer = new NodeJSPackageMetadataNamer(productConfig.getPackageName(), productConfig.getDomainLayerLocation());
    ArrayList<ViewModel> indexViews = new ArrayList<>();
    NodeJSSurfaceNamer namer = new NodeJSSurfaceNamer(productConfig.getPackageName(), NodeJSUtils.isGcloud(productConfig));
    String version = namer.getApiWrapperModuleVersion();
    boolean hasVersion = !Strings.isNullOrEmpty(version);
    ArrayList<VersionIndexRequireView> requireViews = new ArrayList<>();
    for (InterfaceModel apiInterface : apiInterfaces) {
        Name serviceName = namer.getReducedServiceName(apiInterface.getSimpleName());
        String localName = hasVersion ? serviceName.join(version).toLowerCamel() : serviceName.toLowerCamel();
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        ApiMethodView exampleMethod = apiMethodTransformer.generateApiMethods(context).get(0);
        VersionIndexRequireView require = VersionIndexRequireView.newBuilder().clientName(namer.getApiWrapperClassName(productConfig.getInterfaceConfig(apiInterface))).serviceName(namer.getPackageServiceName(context.getInterfaceConfig())).localName(localName).doc(serviceTransformer.generateServiceDoc(context, exampleMethod, productConfig)).fileName(namer.getClientFileName(context.getInterfaceConfig())).build();
        requireViews.add(require);
    }
    String indexOutputPath = hasVersion ? "src/" + version + "/index.js" : "src/index.js";
    VersionIndexView.Builder indexViewbuilder = VersionIndexView.newBuilder().templateFileName(INDEX_TEMPLATE_FILE).outputPath(indexOutputPath).requireViews(requireViews).primaryService(requireViews.get(0)).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).packageName(packageMetadataNamer.getMetadataIdentifier());
    if (hasVersion) {
        indexViewbuilder.apiVersion(version);
    }
    indexViews.add(indexViewbuilder.build());
    String webpackConfigOutputPath = "webpack.config.js";
    VersionIndexView.Builder webpackConfigViewBuilder = VersionIndexView.newBuilder().templateFileName(WEBPACK_CONFIG_TEMPLATE_FILENAME).outputPath(webpackConfigOutputPath).requireViews(requireViews).namespace(packageMetadataNamer.getServiceName()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer));
    indexViews.add(webpackConfigViewBuilder.build());
    if (hasVersion) {
        String versionIndexOutputPath = "src/index.js";
        VersionIndexView.Builder versionIndexViewBuilder = VersionIndexView.newBuilder().templateFileName(VERSION_INDEX_TEMPLATE_FILE).outputPath(versionIndexOutputPath).requireViews(requireViews).primaryService(requireViews.get(0)).apiVersion(version).stubs(versionIndexStubs(apiInterfaces, productConfig)).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).packageName(packageMetadataNamer.getMetadataIdentifier()).namespace(packageMetadataNamer.getServiceName());
        indexViews.add(versionIndexViewBuilder.build());
        String versionBrowserOutputPath = "src/browser.js";
        VersionIndexView.Builder versionBrowserViewBuilder = VersionIndexView.newBuilder().templateFileName(VERSION_BROWSER_TEMPLATE_FILE).outputPath(versionBrowserOutputPath).requireViews(requireViews).primaryService(requireViews.get(0)).apiVersion(version).stubs(versionIndexStubs(apiInterfaces, productConfig)).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).packageName(packageMetadataNamer.getMetadataIdentifier()).namespace(packageMetadataNamer.getServiceName());
        indexViews.add(versionBrowserViewBuilder.build());
    }
    return indexViews;
}
Also used : ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) ArrayList(java.util.ArrayList) VersionIndexView(com.google.api.codegen.viewmodel.metadata.VersionIndexView) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView) Name(com.google.api.codegen.util.Name) InterfaceModel(com.google.api.codegen.config.InterfaceModel)

Example 13 with GapicInterfaceContext

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

the class NodeJSGapicSurfaceTransformer method generateApiClasses.

private List<ViewModel> generateApiClasses(Collection<? extends InterfaceModel> apiInterfaces, GapicProductConfig productConfig) {
    ImmutableList.Builder<ViewModel> models = ImmutableList.builder();
    for (InterfaceModel apiInterface : apiInterfaces) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        models.add(generateApiClass(context));
        models.add(generateProtoList(context));
    }
    return models.build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 14 with GapicInterfaceContext

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

the class NodeJSPackageMetadataTransformer method generateExampleMethods.

// Generates methods used as examples for the README.md file.
// Note: This is based on sample gen method calls. 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(productConfig)) {
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        if (interfaceConfig == null || interfaceConfig.getSmokeTestConfig() == null) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        MethodModel method = interfaceConfig.getSmokeTestConfig().getMethod();
        FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
        GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
        GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(defaultMethodContext, flatteningGroup);
        exampleMethods.add(createExampleApiMethodView(flattenedMethodContext, model.hasMultipleServices()));
    }
    return exampleMethods.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.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.config.GapicInterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 15 with GapicInterfaceContext

use of com.google.api.codegen.config.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.config.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView) HashSet(java.util.HashSet)

Aggregations

GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)32 InterfaceModel (com.google.api.codegen.config.InterfaceModel)28 ViewModel (com.google.api.codegen.viewmodel.ViewModel)20 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)15 ImmutableList (com.google.common.collect.ImmutableList)15 ArrayList (java.util.ArrayList)15 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)10 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)9 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)9 MethodModel (com.google.api.codegen.config.MethodModel)6 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)5 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)5 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)5 HashSet (java.util.HashSet)4 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)3 ApiModel (com.google.api.codegen.config.ApiModel)2 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)2 MethodConfig (com.google.api.codegen.config.MethodConfig)2 MethodContext (com.google.api.codegen.config.MethodContext)2 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)2