Search in sources :

Example 1 with GrpcDocView

use of com.google.api.codegen.viewmodel.GrpcDocView 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 2 with GrpcDocView

use of com.google.api.codegen.viewmodel.GrpcDocView in project toolkit by googleapis.

the class PythonGapicSurfaceTransformer method generateServiceSurfaces.

private Iterable<ViewModel> generateServiceSurfaces(ProtoApiModel apiModel, GapicProductConfig productConfig) {
    ModelTypeTable modelTypeTable = new ModelTypeTable(new PythonTypeTable(productConfig.getPackageName()), new PythonModelTypeNameConverter(productConfig.getPackageName()));
    SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
    FeatureConfig featureConfig = new DefaultFeatureConfig();
    ImmutableList.Builder<ViewModel> serviceSurfaces = ImmutableList.builder();
    for (InterfaceModel apiInterface : apiModel.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, modelTypeTable, namer, featureConfig);
        addApiImports(context);
        String subPath = pathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
        DynamicLangXApiView.Builder serviceClass = generateApiView(context);
        serviceClass.templateFileName(XAPI_TEMPLATE_FILENAME);
        serviceClass.outputPath(namer.getSourceFilePath(subPath, namer.getApiWrapperClassName(context.getInterfaceConfig())));
        serviceClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));
        serviceSurfaces.add(serviceClass.build());
        DynamicLangXApiView.Builder grpcTransportClass = generateApiView(context);
        grpcTransportClass.templateFileName(TRANSPORT_TEMPLATE_FILENAME);
        grpcTransportClass.outputPath(namer.getSourceFilePath(subPath + "/transports", namer.getGrpcTransportClassName(context.getInterfaceConfig())));
        ImportSectionView grpcTransportImportSection = importSectionTransformer.generateGrpcTransportImportSection(context);
        grpcTransportClass.fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, grpcTransportImportSection, namer));
        serviceSurfaces.add(grpcTransportClass.build());
    }
    GrpcDocView enumFile = generateEnumView(productConfig, modelTypeTable, namer, apiModel.getProtoModel().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.config.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) DefaultFeatureConfig(com.google.api.codegen.transformer.DefaultFeatureConfig) DynamicLangXApiView(com.google.api.codegen.viewmodel.DynamicLangXApiView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

InterfaceModel (com.google.api.codegen.config.InterfaceModel)2 DefaultFeatureConfig (com.google.api.codegen.transformer.DefaultFeatureConfig)2 FeatureConfig (com.google.api.codegen.transformer.FeatureConfig)2 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)2 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)2 PythonTypeTable (com.google.api.codegen.util.py.PythonTypeTable)2 GrpcDocView (com.google.api.codegen.viewmodel.GrpcDocView)2 ViewModel (com.google.api.codegen.viewmodel.ViewModel)2 ImmutableList (com.google.common.collect.ImmutableList)2 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)1 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)1 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)1 DynamicLangXApiView (com.google.api.codegen.viewmodel.DynamicLangXApiView)1 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)1