Search in sources :

Example 6 with ProtoApiModel

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

the class PythonGrpcPackageGenerator method generate.

@Override
public Map<String, GeneratedResult<Doc>> generate() throws IOException {
    ImmutableMap.Builder<String, GeneratedResult<Doc>> results = new ImmutableMap.Builder<>();
    ArrayList<PackageMetadataView> metadataViews = new ArrayList<>();
    PythonPackageCopier copier = new PythonPackageCopier();
    PythonPackageCopierResult copierResult = copier.run(options, config);
    results.putAll(copierResult.results());
    PythonGrpcPackageTransformer pythonTransformer = new PythonGrpcPackageTransformer(copierResult);
    ProtoApiModel apiModel = new ProtoApiModel(model);
    metadataViews.addAll(pythonTransformer.transform(apiModel, config));
    for (PackageMetadataView view : metadataViews) {
        CommonSnippetSetRunner runner = new CommonSnippetSetRunner(view, false);
        results.putAll(runner.generate(view));
    }
    return results.build();
}
Also used : CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) GeneratedResult(com.google.api.codegen.common.GeneratedResult) ArrayList(java.util.ArrayList) ImmutableMap(com.google.common.collect.ImmutableMap) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) PackageMetadataView(com.google.api.codegen.viewmodel.metadata.PackageMetadataView)

Example 7 with ProtoApiModel

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

the class JavaGrpcPackageGenerator method generate.

@Override
public Map<String, GeneratedResult<Doc>> generate() {
    ImmutableMap.Builder<String, GeneratedResult<Doc>> results = new ImmutableMap.Builder<>();
    ProtoApiModel apiModel = new ProtoApiModel(model);
    List<PackageMetadataView> metadataViews = transformer.transform(apiModel, config);
    for (PackageMetadataView view : metadataViews) {
        CommonSnippetSetRunner runner = new CommonSnippetSetRunner(view, false);
        results.putAll(runner.generate(view));
    }
    return results.build();
}
Also used : CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) GeneratedResult(com.google.api.codegen.common.GeneratedResult) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) PackageMetadataView(com.google.api.codegen.viewmodel.metadata.PackageMetadataView) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 8 with ProtoApiModel

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

the class RubySamplePackageMetadataTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
    boolean shouldGenerateSamplePackages = productConfig.getInterfaceConfigMap().values().stream().flatMap(config -> config.getMethodConfigs().stream()).anyMatch(config -> config.getSampleSpec().isConfigured());
    if (!shouldGenerateSamplePackages) {
        return Collections.emptyList();
    }
    ViewModel rubySampleGemfileView = new RubySampleGemfileView() {

        @Override
        public String gapicGemName() {
            return RubySamplePackageMetadataTransformer.gapicGemName(packageConfig.packageName());
        }
    };
    return Collections.singletonList(rubySampleGemfileView);
}
Also used : SnippetSetRunner(com.google.api.codegen.SnippetSetRunner) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) List(java.util.List) Stream(java.util.stream.Stream) PackageMetadataConfig(com.google.api.codegen.config.PackageMetadataConfig) ViewModel(com.google.api.codegen.viewmodel.ViewModel) VersionMatcher(com.google.api.codegen.util.VersionMatcher) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ModelToViewTransformer(com.google.api.codegen.transformer.ModelToViewTransformer) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 9 with ProtoApiModel

use of com.google.api.codegen.config.ProtoApiModel 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 10 with ProtoApiModel

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

Aggregations

ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)15 ViewModel (com.google.api.codegen.viewmodel.ViewModel)9 ImmutableList (com.google.common.collect.ImmutableList)6 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)5 CommonSnippetSetRunner (com.google.api.codegen.rendering.CommonSnippetSetRunner)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 GeneratedResult (com.google.api.codegen.common.GeneratedResult)3 PackageMetadataConfig (com.google.api.codegen.config.PackageMetadataConfig)3 ModelToViewTransformer (com.google.api.codegen.transformer.ModelToViewTransformer)3 PackageMetadataView (com.google.api.codegen.viewmodel.metadata.PackageMetadataView)3 Function (java.util.function.Function)3 SnippetSetRunner (com.google.api.codegen.SnippetSetRunner)2 TargetLanguage (com.google.api.codegen.common.TargetLanguage)2 ApiModel (com.google.api.codegen.config.ApiModel)2 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)2 InterfaceContext (com.google.api.codegen.config.InterfaceContext)2 InterfaceModel (com.google.api.codegen.config.InterfaceModel)2 MethodModel (com.google.api.codegen.config.MethodModel)2