Search in sources :

Example 21 with GapicInterfaceContext

use of com.google.api.codegen.transformer.GapicInterfaceContext 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 22 with GapicInterfaceContext

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

the class RubyGapicSurfaceTestTransformer method createUnitTestViews.

// /////////////////////////////////// Unit Test ///////////////////////////////////////
private List<ClientTestFileView> createUnitTestViews(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ClientTestFileView> views = ImmutableList.builder();
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        String testClassName = namer.getUnitTestClassName(context.getInterfaceConfig());
        String outputPath = unitTestPathMapper.getOutputPath(context.getInterfaceModel().getFullName(), productConfig);
        ImportSectionView importSection = importSectionTransformer.generateTestImportSection(context);
        views.add(ClientTestFileView.newBuilder().templateFileName(UNIT_TEST_TEMPLATE_FILE).outputPath(namer.getSourceFilePath(outputPath, testClassName)).testClass(createUnitTestClassView(context, model.hasMultipleServices())).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).apiVersion(packageConfig.apiVersion()).build());
    }
    return views.build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ClientTestFileView(com.google.api.codegen.viewmodel.testing.ClientTestFileView) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 23 with GapicInterfaceContext

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

the class RubyGapicSurfaceTransformer method generateTopLevelIndexView.

private ViewModel generateTopLevelIndexView(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    ImmutableList.Builder<VersionIndexRequireView> requireViews = ImmutableList.builder();
    List<String> modules = namer.getTopLevelApiModules();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        String clientName = namer.getPackageName();
        String serviceName = namer.getPackageServiceName(context.getInterfaceConfig());
        if (model.hasMultipleServices()) {
            clientName += "::" + serviceName;
        }
        String topLevelNamespace = namer.getTopLevelNamespace();
        requireViews.add(VersionIndexRequireView.newBuilder().clientName(clientName).serviceName(serviceName).fileName(versionPackagePath(namer)).topLevelNamespace(topLevelNamespace).doc(serviceTransformer.generateServiceDoc(context, generateApiMethods(context).get(0), productConfig)).build());
    }
    String versionFileBasePath = namer.packageFilePathPiece(Name.upperCamel(modules.get(modules.size() - 1)));
    return VersionIndexView.newBuilder().apiVersion(packageConfig.apiVersion()).requireViews(requireViews.build()).templateFileName(VERSION_INDEX_TEMPLATE_FILE).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.RUBY).lower()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).outputPath("lib" + File.separator + topLevelPackagePath(namer) + ".rb").modules(generateModuleViews(model, productConfig, false)).type(VersionIndexType.TopLevelIndex).versionFileBasePath(versionFileBasePath).toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()).build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)

Example 24 with GapicInterfaceContext

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

the class RubyGapicSurfaceTransformer method generateApiClasses.

private List<ViewModel> generateApiClasses(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    FeatureConfig featureConfig = new RubyFeatureConfig();
    ImmutableList.Builder<ViewModel> serviceSurfaces = ImmutableList.builder();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        String packageName = productConfig.getPackageName();
        ModelTypeTable modelTypeTable = new ModelTypeTable(new RubyTypeTable(productConfig.getPackageName()), new RubyModelTypeNameConverter(packageName));
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, modelTypeTable, namer, featureConfig);
        serviceSurfaces.add(generateApiClass(context, packageName));
    }
    return serviceSurfaces.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FeatureConfig(com.google.api.codegen.transformer.FeatureConfig) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceModel(com.google.api.codegen.config.InterfaceModel) RubyTypeTable(com.google.api.codegen.util.ruby.RubyTypeTable) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 25 with GapicInterfaceContext

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

the class RubyImportSectionTransformer method generateImportSection.

@Override
public ImportSectionView generateImportSection(TransformationContext transformationContext, String className) {
    // TODO support non-Gapic inputs
    GapicInterfaceContext context = (GapicInterfaceContext) transformationContext;
    Set<String> importFilenames = generateImportFilenames(context);
    ImportSectionView.Builder importSection = ImportSectionView.newBuilder();
    importSection.standardImports(generateStandardImports());
    importSection.externalImports(generateExternalImports(context));
    importSection.appImports(generateAppImports(context, importFilenames));
    importSection.serviceImports(generateServiceImports(context, importFilenames));
    return importSection.build();
}
Also used : GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)27 InterfaceModel (com.google.api.codegen.config.InterfaceModel)24 ViewModel (com.google.api.codegen.viewmodel.ViewModel)16 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)13 ArrayList (java.util.ArrayList)13 ImmutableList (com.google.common.collect.ImmutableList)12 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)9 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)7 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)4 MethodModel (com.google.api.codegen.config.MethodModel)4 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)4 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)3 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)3 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)2 FeatureConfig (com.google.api.codegen.transformer.FeatureConfig)2 VersionIndexRequireView (com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)2 MockServiceImplView (com.google.api.codegen.viewmodel.testing.MockServiceImplView)2 HashSet (java.util.HashSet)2 TargetLanguage (com.google.api.codegen.TargetLanguage)1 ApiModel (com.google.api.codegen.config.ApiModel)1