Search in sources :

Example 1 with CommonSnippetSetRunner

use of com.google.api.codegen.rendering.CommonSnippetSetRunner in project toolkit by googleapis.

the class JavaGrpcMetadataProvider method generate.

@Override
public Map<String, Doc> generate(Model model, PackageMetadataConfig config) {
    ImmutableMap.Builder<String, Doc> docs = new ImmutableMap.Builder<>();
    ProtoApiModel apiModel = new ProtoApiModel(model);
    ArrayList<PackageMetadataView> metadataViews = new ArrayList<>();
    metadataViews.addAll(transformer.transform(apiModel, config));
    for (PackageMetadataView view : metadataViews) {
        CommonSnippetSetRunner runner = new CommonSnippetSetRunner(view);
        Doc result = runner.generate(view);
        if (!result.isWhitespace()) {
            docs.put(view.outputPath(), result);
        }
    }
    return docs.build();
}
Also used : CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) ArrayList(java.util.ArrayList) Doc(com.google.api.tools.framework.snippet.Doc) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) PackageMetadataView(com.google.api.codegen.viewmodel.metadata.PackageMetadataView) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with CommonSnippetSetRunner

use of com.google.api.codegen.rendering.CommonSnippetSetRunner in project toolkit by googleapis.

the class MainDiscoGapicProviderFactory method defaultCreate.

/**
 * Create the DiscoGapicProvider based on the given id
 */
public static List<GapicProvider> defaultCreate(DiscoApiModel model, GapicProductConfig productConfig, GapicGeneratorConfig generatorConfig, PackageMetadataConfig packageConfig) {
    ArrayList<GapicProvider> providers = new ArrayList<>();
    String id = generatorConfig.id();
    // Please keep the following IDs in alphabetical order
    if (id.equals(JAVA)) {
        if (generatorConfig.enableSurfaceGenerator()) {
            GapicCodePathMapper javaPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("src/main/java").setShouldAppendPackage(true).build();
            List<DocumentToViewTransformer> transformers = Arrays.asList(new JavaDiscoGapicResourceNameToViewTransformer(javaPathMapper, packageConfig), new JavaDiscoGapicSchemaToViewTransformer(javaPathMapper, packageConfig), new JavaDiscoGapicRequestToViewTransformer(javaPathMapper, packageConfig), new JavaDiscoGapicSurfaceTransformer(javaPathMapper, packageConfig));
            DiscoGapicProvider provider = DiscoGapicProvider.newBuilder().setDiscoApiModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new JavaRenderingUtil())).setDocumentToViewTransformers(transformers).build();
            providers.add(provider);
        }
        if (generatorConfig.enableTestGenerator()) {
            GapicCodePathMapper javaTestPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("src/test/java").setShouldAppendPackage(true).build();
            GapicProvider testProvider = ViewModelDiscoGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new JavaSurfaceTestTransformer(javaTestPathMapper, new JavaDiscoGapicSurfaceTransformer(javaTestPathMapper, packageConfig), "java/http_test.snip")).build();
            providers.add(testProvider);
        }
        return providers;
    } else {
        throw new NotImplementedException("DiscoGapicProviderFactory: invalid id \"" + id + "\"");
    }
}
Also used : JavaDiscoGapicResourceNameToViewTransformer(com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicResourceNameToViewTransformer) JavaDiscoGapicRequestToViewTransformer(com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicRequestToViewTransformer) CommonGapicCodePathMapper(com.google.api.codegen.gapic.CommonGapicCodePathMapper) GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) JavaRenderingUtil(com.google.api.codegen.util.java.JavaRenderingUtil) NotImplementedException(org.apache.commons.lang3.NotImplementedException) GapicProvider(com.google.api.codegen.gapic.GapicProvider) ArrayList(java.util.ArrayList) JavaSurfaceTestTransformer(com.google.api.codegen.transformer.java.JavaSurfaceTestTransformer) JavaDiscoGapicSchemaToViewTransformer(com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSchemaToViewTransformer) JavaDiscoGapicSurfaceTransformer(com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSurfaceTransformer) CommonRenderingUtil(com.google.api.codegen.util.CommonRenderingUtil) DocumentToViewTransformer(com.google.api.codegen.discogapic.transformer.DocumentToViewTransformer)

Example 3 with CommonSnippetSetRunner

use of com.google.api.codegen.rendering.CommonSnippetSetRunner in project toolkit by googleapis.

the class MainGapicProviderFactory method defaultCreate.

/**
 * Create the GapicProviders based on the given id
 */
public static List<GapicProvider> defaultCreate(Model model, GapicProductConfig productConfig, GapicGeneratorConfig generatorConfig, PackageMetadataConfig packageConfig) {
    ArrayList<GapicProvider> providers = new ArrayList<>();
    String id = generatorConfig.id();
    // Please keep the following IDs in alphabetical order
    if (id.equals(CLIENT_CONFIG)) {
        GapicProvider provider = CommonGapicProvider.<Interface>newBuilder().setModel(model).setView(new InterfaceView()).setContext(new ClientConfigGapicContext(model, productConfig)).setSnippetSetRunner(new ClientConfigSnippetSetRunner<>(SnippetSetRunner.SNIPPET_RESOURCE_ROOT)).setSnippetFileNames(Arrays.asList("clientconfig/json.snip")).setCodePathMapper(CommonGapicCodePathMapper.defaultInstance()).build();
        providers.add(provider);
    } else if (id.equals(CSHARP)) {
        String packageName = productConfig.getPackageName();
        if (generatorConfig.enableSurfaceGenerator()) {
            GapicCodePathMapper pathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix(packageName + File.separator + packageName).setPackageFilePathNameFormatter(new CSharpNameFormatter()).build();
            GapicProvider mainProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CSharpRenderingUtil())).setModelToViewTransformer(new CSharpGapicClientTransformer(pathMapper, packageConfig)).build();
            providers.add(mainProvider);
            GapicCodePathMapper snippetPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix(packageName + File.separator + packageName + ".Snippets").setPackageFilePathNameFormatter(new CSharpNameFormatter()).build();
            GapicProvider snippetProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CSharpRenderingUtil())).setModelToViewTransformer(new CSharpGapicSnippetsTransformer(snippetPathMapper)).build();
            providers.add(snippetProvider);
        }
        if (generatorConfig.enableTestGenerator()) {
            GapicCodePathMapper smokeTestPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix(packageName + File.separator + packageName + ".SmokeTests").setPackageFilePathNameFormatter(new CSharpNameFormatter()).build();
            GapicProvider smokeTestProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CSharpRenderingUtil())).setModelToViewTransformer(new CSharpGapicSmokeTestTransformer(smokeTestPathMapper)).build();
            providers.add(smokeTestProvider);
            GapicCodePathMapper unitTestPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix(packageName + File.separator + packageName + ".Tests").setPackageFilePathNameFormatter(new CSharpNameFormatter()).build();
            GapicProvider unitTestProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CSharpRenderingUtil())).setModelToViewTransformer(new CSharpGapicUnitTestTransformer(unitTestPathMapper)).build();
            providers.add(unitTestProvider);
        }
    } else if (id.equals(GO)) {
        if (generatorConfig.enableSurfaceGenerator()) {
            GapicProvider provider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new GoGapicSurfaceTransformer(new PackageNameCodePathMapper())).build();
            providers.add(provider);
        }
        if (generatorConfig.enableTestGenerator()) {
            GapicProvider testProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new GoGapicSurfaceTestTransformer()).build();
            providers.add(testProvider);
        }
    } else if (id.equals(JAVA)) {
        if (generatorConfig.enableSurfaceGenerator()) {
            GapicCodePathMapper javaPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("src/main/java").setShouldAppendPackage(true).build();
            GapicProvider mainProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new JavaRenderingUtil())).setModelToViewTransformer(new JavaGapicSurfaceTransformer(javaPathMapper, packageConfig)).build();
            providers.add(mainProvider);
            GapicProvider metadataProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new JavaRenderingUtil())).setModelToViewTransformer(new JavaGapicMetadataTransformer(packageConfig)).build();
            providers.add(metadataProvider);
        }
        if (generatorConfig.enableTestGenerator()) {
            GapicCodePathMapper javaTestPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("src/test/java").setShouldAppendPackage(true).build();
            GapicProvider testProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new JavaSurfaceTestTransformer(javaTestPathMapper, new JavaGapicSurfaceTransformer(javaTestPathMapper, packageConfig), "java/grpc_test.snip")).build();
            providers.add(testProvider);
        }
        return providers;
    } else if (id.equals(NODEJS) || id.equals(NODEJS_DOC)) {
        if (generatorConfig.enableSurfaceGenerator()) {
            GapicCodePathMapper nodeJSPathMapper = new NodeJSCodePathMapper();
            GapicProvider mainProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new NodeJSGapicSurfaceTransformer(nodeJSPathMapper, packageConfig)).build();
            GapicProvider metadataProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new NodeJSPackageMetadataTransformer(packageConfig)).build();
            GapicProvider clientConfigProvider = CommonGapicProvider.<Interface>newBuilder().setModel(model).setView(new InterfaceView()).setContext(new ClientConfigGapicContext(model, productConfig)).setSnippetSetRunner(new ClientConfigSnippetSetRunner<>(SnippetSetRunner.SNIPPET_RESOURCE_ROOT)).setSnippetFileNames(Arrays.asList("clientconfig/json.snip")).setCodePathMapper(nodeJSPathMapper).build();
            providers.add(mainProvider);
            providers.add(metadataProvider);
            providers.add(clientConfigProvider);
            if (id.equals(NODEJS_DOC)) {
                GapicProvider messageProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new NodeJSGapicSurfaceDocTransformer()).build();
                providers.add(messageProvider);
            }
        }
        if (generatorConfig.enableTestGenerator()) {
            GapicProvider testProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new NodeJSGapicSurfaceTestTransformer()).build();
            providers.add(testProvider);
        }
    } else if (id.equals(PHP)) {
        if (generatorConfig.enableSurfaceGenerator()) {
            GapicCodePathMapper phpPathMapper = PhpGapicCodePathMapper.newBuilder().setPrefix("src").build();
            GapicProvider provider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new PhpGapicSurfaceTransformer(productConfig, phpPathMapper, model)).build();
            GapicCodePathMapper phpClientConfigPathMapper = PhpGapicCodePathMapper.newBuilder().setPrefix("src").setSuffix("resources").build();
            GapicProvider clientConfigProvider = CommonGapicProvider.<Interface>newBuilder().setModel(model).setView(new InterfaceView()).setContext(new PhpClientConfigGapicContext(model, productConfig)).setSnippetSetRunner(new ClientConfigSnippetSetRunner<>(SnippetSetRunner.SNIPPET_RESOURCE_ROOT)).setSnippetFileNames(Arrays.asList("clientconfig/json.snip")).setCodePathMapper(phpClientConfigPathMapper).build();
            GapicProvider metadataProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new PhpPackageMetadataTransformer(packageConfig)).build();
            providers.add(provider);
            providers.add(clientConfigProvider);
            providers.add(metadataProvider);
        }
        if (generatorConfig.enableTestGenerator()) {
            GapicProvider testProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new PhpGapicSurfaceTestTransformer()).build();
            providers.add(testProvider);
        }
    } else if (id.equals(PYTHON)) {
        if (generatorConfig.enableSurfaceGenerator()) {
            GapicCodePathMapper pythonPathMapper = CommonGapicCodePathMapper.newBuilder().setShouldAppendPackage(true).build();
            GapicProvider mainProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new PythonRenderingUtil())).setModelToViewTransformer(new PythonGapicSurfaceTransformer(pythonPathMapper, packageConfig)).build();
            GapicProvider clientConfigProvider = CommonGapicProvider.<Interface>newBuilder().setModel(model).setView(new InterfaceView()).setContext(new ClientConfigGapicContext(model, productConfig)).setSnippetSetRunner(new ClientConfigSnippetSetRunner<>(SnippetSetRunner.SNIPPET_RESOURCE_ROOT)).setSnippetFileNames(Arrays.asList("clientconfig/python_clientconfig.snip")).setCodePathMapper(pythonPathMapper).build();
            providers.add(mainProvider);
            providers.add(clientConfigProvider);
            GapicProvider metadataProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new PythonRenderingUtil())).setModelToViewTransformer(new PythonPackageMetadataTransformer(packageConfig)).build();
            providers.add(metadataProvider);
        }
        if (generatorConfig.enableTestGenerator()) {
            GapicCodePathMapper pythonTestPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("test").setShouldAppendPackage(true).build();
            GapicProvider testProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new PythonGapicSurfaceTestTransformer(pythonTestPathMapper, packageConfig)).build();
            providers.add(testProvider);
        }
    } else if (id.equals(RUBY) || id.equals(RUBY_DOC)) {
        if (generatorConfig.enableSurfaceGenerator()) {
            GapicCodePathMapper rubyPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("lib").setShouldAppendPackage(true).setPackageFilePathNameFormatter(new RubyNameFormatter()).build();
            GapicProvider mainProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new RubyGapicSurfaceTransformer(rubyPathMapper, packageConfig)).build();
            GapicProvider clientConfigProvider = CommonGapicProvider.<Interface>newBuilder().setModel(model).setView(new InterfaceView()).setContext(new ClientConfigGapicContext(model, productConfig)).setSnippetSetRunner(new ClientConfigSnippetSetRunner<>(SnippetSetRunner.SNIPPET_RESOURCE_ROOT)).setSnippetFileNames(Arrays.asList("clientconfig/json.snip")).setCodePathMapper(rubyPathMapper).build();
            GapicProvider metadataProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new RubyPackageMetadataTransformer(packageConfig)).build();
            providers.add(mainProvider);
            providers.add(clientConfigProvider);
            providers.add(metadataProvider);
            if (id.equals(RUBY_DOC)) {
                GapicProvider messageProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new RubyGapicSurfaceDocTransformer(rubyPathMapper, packageConfig)).build();
                providers.add(messageProvider);
            }
        }
        if (generatorConfig.enableTestGenerator()) {
            CommonGapicCodePathMapper.Builder rubyTestPathMapperBuilder = CommonGapicCodePathMapper.newBuilder().setShouldAppendPackage(true).setPackageFilePathNameFormatter(new RubyNameFormatter());
            GapicProvider testProvider = ViewModelGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new RubyGapicSurfaceTestTransformer(rubyTestPathMapperBuilder.setPrefix("test").build(), rubyTestPathMapperBuilder.setPrefix("acceptance").build(), packageConfig)).build();
            providers.add(testProvider);
        }
    } else {
        throw new NotImplementedException("GapicProviderFactory: invalid id \"" + id + "\"");
    }
    if (providers.isEmpty()) {
        throw new IllegalArgumentException("No artifacts are enabled.");
    }
    return providers;
}
Also used : GoGapicSurfaceTestTransformer(com.google.api.codegen.transformer.go.GoGapicSurfaceTestTransformer) PhpClientConfigGapicContext(com.google.api.codegen.clientconfig.php.PhpClientConfigGapicContext) ClientConfigGapicContext(com.google.api.codegen.clientconfig.ClientConfigGapicContext) NodeJSCodePathMapper(com.google.api.codegen.nodejs.NodeJSCodePathMapper) RubyGapicSurfaceTestTransformer(com.google.api.codegen.transformer.ruby.RubyGapicSurfaceTestTransformer) CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) JavaRenderingUtil(com.google.api.codegen.util.java.JavaRenderingUtil) NotImplementedException(org.apache.commons.lang3.NotImplementedException) ArrayList(java.util.ArrayList) PythonGapicSurfaceTestTransformer(com.google.api.codegen.transformer.py.PythonGapicSurfaceTestTransformer) RubyNameFormatter(com.google.api.codegen.util.ruby.RubyNameFormatter) JavaGapicSurfaceTransformer(com.google.api.codegen.transformer.java.JavaGapicSurfaceTransformer) PythonRenderingUtil(com.google.api.codegen.util.py.PythonRenderingUtil) NodeJSPackageMetadataTransformer(com.google.api.codegen.transformer.nodejs.NodeJSPackageMetadataTransformer) GoGapicSurfaceTransformer(com.google.api.codegen.transformer.go.GoGapicSurfaceTransformer) CommonRenderingUtil(com.google.api.codegen.util.CommonRenderingUtil) PhpPackageMetadataTransformer(com.google.api.codegen.transformer.php.PhpPackageMetadataTransformer) RubyGapicSurfaceTransformer(com.google.api.codegen.transformer.ruby.RubyGapicSurfaceTransformer) NodeJSGapicSurfaceTransformer(com.google.api.codegen.transformer.nodejs.NodeJSGapicSurfaceTransformer) RubyGapicSurfaceDocTransformer(com.google.api.codegen.transformer.ruby.RubyGapicSurfaceDocTransformer) JavaGapicMetadataTransformer(com.google.api.codegen.transformer.java.JavaGapicMetadataTransformer) PhpGapicSurfaceTestTransformer(com.google.api.codegen.transformer.php.PhpGapicSurfaceTestTransformer) NodeJSGapicSurfaceDocTransformer(com.google.api.codegen.transformer.nodejs.NodeJSGapicSurfaceDocTransformer) CSharpGapicClientTransformer(com.google.api.codegen.transformer.csharp.CSharpGapicClientTransformer) RubyPackageMetadataTransformer(com.google.api.codegen.transformer.ruby.RubyPackageMetadataTransformer) PhpGapicCodePathMapper(com.google.api.codegen.php.PhpGapicCodePathMapper) ClientConfigSnippetSetRunner(com.google.api.codegen.clientconfig.ClientConfigSnippetSetRunner) PhpClientConfigGapicContext(com.google.api.codegen.clientconfig.php.PhpClientConfigGapicContext) CSharpRenderingUtil(com.google.api.codegen.util.csharp.CSharpRenderingUtil) JavaSurfaceTestTransformer(com.google.api.codegen.transformer.java.JavaSurfaceTestTransformer) PhpGapicSurfaceTransformer(com.google.api.codegen.transformer.php.PhpGapicSurfaceTransformer) CSharpNameFormatter(com.google.api.codegen.util.csharp.CSharpNameFormatter) CSharpGapicSmokeTestTransformer(com.google.api.codegen.transformer.csharp.CSharpGapicSmokeTestTransformer) NodeJSGapicSurfaceTestTransformer(com.google.api.codegen.transformer.nodejs.NodeJSGapicSurfaceTestTransformer) PythonPackageMetadataTransformer(com.google.api.codegen.transformer.py.PythonPackageMetadataTransformer) CSharpGapicUnitTestTransformer(com.google.api.codegen.transformer.csharp.CSharpGapicUnitTestTransformer) PythonGapicSurfaceTransformer(com.google.api.codegen.transformer.py.PythonGapicSurfaceTransformer) CSharpGapicSnippetsTransformer(com.google.api.codegen.transformer.csharp.CSharpGapicSnippetsTransformer) InterfaceView(com.google.api.codegen.InterfaceView) Interface(com.google.api.tools.framework.model.Interface)

Example 4 with CommonSnippetSetRunner

use of com.google.api.codegen.rendering.CommonSnippetSetRunner in project toolkit by googleapis.

the class PythonGrpcMetadataProvider method generate.

@Override
public Map<String, Doc> generate(Model model, PackageMetadataConfig config) throws IOException {
    ImmutableMap.Builder<String, Doc> docs = new ImmutableMap.Builder<String, Doc>();
    ArrayList<PackageMetadataView> metadataViews = new ArrayList<>();
    PythonPackageCopier copier = new PythonPackageCopier();
    PythonPackageCopierResult copierResult = copier.run(options, config);
    docs.putAll(copierResult.docs());
    PythonGrpcMetadataTransformer pythonTransformer = new PythonGrpcMetadataTransformer(copierResult);
    ProtoApiModel apiModel = new ProtoApiModel(model);
    metadataViews.addAll(pythonTransformer.transform(apiModel, config));
    for (PackageMetadataView view : metadataViews) {
        CommonSnippetSetRunner runner = new CommonSnippetSetRunner(view);
        Doc result = runner.generate(view);
        if (!result.isWhitespace()) {
            docs.put(view.outputPath(), result);
        }
    }
    return docs.build();
}
Also used : CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) ArrayList(java.util.ArrayList) ImmutableMap(com.google.common.collect.ImmutableMap) Doc(com.google.api.tools.framework.snippet.Doc) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) PackageMetadataView(com.google.api.codegen.viewmodel.metadata.PackageMetadataView)

Example 5 with CommonSnippetSetRunner

use of com.google.api.codegen.rendering.CommonSnippetSetRunner in project toolkit by googleapis.

the class DiscoConfigGeneratorApi method generateConfig.

private Map<String, Doc> generateConfig(String outputPath) {
    Document document = setupDocument();
    ViewModel viewModel = new DiscoConfigTransformer().generateConfig(new DiscoApiModel(document, ""), outputPath);
    Doc generatedConfig = new CommonSnippetSetRunner(new CommonRenderingUtil()).generate(viewModel);
    return ImmutableMap.of(outputPath, generatedConfig);
}
Also used : DiscoApiModel(com.google.api.codegen.config.DiscoApiModel) CommonRenderingUtil(com.google.api.codegen.util.CommonRenderingUtil) CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) Doc(com.google.api.tools.framework.snippet.Doc) ViewModel(com.google.api.codegen.viewmodel.ViewModel) DiscoConfigTransformer(com.google.api.codegen.configgen.transformer.DiscoConfigTransformer) Document(com.google.api.codegen.discovery.Document)

Aggregations

CommonSnippetSetRunner (com.google.api.codegen.rendering.CommonSnippetSetRunner)5 ArrayList (java.util.ArrayList)4 CommonRenderingUtil (com.google.api.codegen.util.CommonRenderingUtil)3 Doc (com.google.api.tools.framework.snippet.Doc)3 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)2 JavaSurfaceTestTransformer (com.google.api.codegen.transformer.java.JavaSurfaceTestTransformer)2 JavaRenderingUtil (com.google.api.codegen.util.java.JavaRenderingUtil)2 InterfaceView (com.google.api.codegen.InterfaceView)1 ClientConfigGapicContext (com.google.api.codegen.clientconfig.ClientConfigGapicContext)1 ClientConfigSnippetSetRunner (com.google.api.codegen.clientconfig.ClientConfigSnippetSetRunner)1 PhpClientConfigGapicContext (com.google.api.codegen.clientconfig.php.PhpClientConfigGapicContext)1 DiscoApiModel (com.google.api.codegen.config.DiscoApiModel)1 DiscoConfigTransformer (com.google.api.codegen.configgen.transformer.DiscoConfigTransformer)1 DocumentToViewTransformer (com.google.api.codegen.discogapic.transformer.DocumentToViewTransformer)1 JavaDiscoGapicRequestToViewTransformer (com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicRequestToViewTransformer)1 JavaDiscoGapicResourceNameToViewTransformer (com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicResourceNameToViewTransformer)1 JavaDiscoGapicSchemaToViewTransformer (com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSchemaToViewTransformer)1 JavaDiscoGapicSurfaceTransformer (com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSurfaceTransformer)1 Document (com.google.api.codegen.discovery.Document)1 CommonGapicCodePathMapper (com.google.api.codegen.gapic.CommonGapicCodePathMapper)1