Search in sources :

Example 11 with ModelTypeTable

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

the class NodeJSGapicSurfaceTestTransformer method generateTestView.

private MockCombinedView generateTestView(ApiModel model, GapicProductConfig productConfig, SurfaceNamer namer) {
    ModelTypeTable typeTable = createTypeTable(productConfig);
    List<MockServiceImplView> impls = new ArrayList<>();
    List<ClientTestClassView> testClasses = new ArrayList<>();
    for (InterfaceModel apiInterface : mockServiceTransformer.getGrpcInterfacesToMock(model, productConfig)) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, namer, featureConfig);
        impls.add(MockServiceImplView.newBuilder().mockGrpcClassName(namer.getGrpcServerTypeName(context.getInterfaceModel())).name(namer.getMockGrpcServiceImplName(apiInterface)).grpcMethods(mockServiceTransformer.createMockGrpcMethodViews(context)).build());
    }
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        // We don't need any imports here.
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(productConfig), namer, featureConfig);
        testClasses.add(ClientTestClassView.newBuilder().apiSettingsClassName(namer.getNotImplementedString("NodeJSGapicSurfaceTestTransformer.generateTestView - apiSettingsClassName")).apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig())).name(namer.getNotImplementedString("NodeJSGapicSurfaceTestTransformer.generateTestView - name")).testCases(createTestCaseViews(context)).apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations()).packageServiceName(namer.getPackageServiceName(context.getInterfaceConfig())).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockServices(Collections.<MockServiceUsageView>emptyList()).build());
    }
    ImportSectionView importSection = importSectionTransformer.generateImportSection(typeTable.getImports(), null);
    return MockCombinedView.newBuilder().outputPath(testCaseOutputFile(namer)).serviceImpls(impls).mockServices(new ArrayList<MockServiceUsageView>()).testClasses(testClasses).localPackageName(namer.getLocalPackageName()).templateFileName(TEST_TEMPLATE_FILE).packageHasMultipleServices(model.hasMultipleServices()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).build();
}
Also used : MockServiceUsageView(com.google.api.codegen.viewmodel.testing.MockServiceUsageView) MockServiceImplView(com.google.api.codegen.viewmodel.testing.MockServiceImplView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) ArrayList(java.util.ArrayList) ClientTestClassView(com.google.api.codegen.viewmodel.testing.ClientTestClassView) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 12 with ModelTypeTable

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

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

the class PythonImportSectionTransformer method generateTypesProtoImports.

private List<ImportFileView> generateTypesProtoImports(Model model, GapicProductConfig productConfig) {
    ModelTypeTable typeTable = emptyTypeTable(productConfig);
    Set<ImportFileView> imports = new TreeSet<>(importFileViewComparator());
    // Save proto file import names to the type table for disambiguation.
    List<ProtoFile> protoFileDependencies = model.getFiles();
    populateTypeTable(protoFileDependencies, typeTable);
    // Get disambiguated imports.
    for (Map.Entry<String, TypeAlias> entry : typeTable.getImports().entrySet()) {
        imports.add(generateAppImport(entry.getKey(), entry.getValue().getNickname()));
    }
    return ImmutableList.<ImportFileView>builder().addAll(imports).build();
}
Also used : ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) TreeSet(java.util.TreeSet) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) ProtoFile(com.google.api.tools.framework.model.ProtoFile) TypeAlias(com.google.api.codegen.util.TypeAlias) Map(java.util.Map)

Example 14 with ModelTypeTable

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

the class RubyGapicSurfaceDocTransformer method generateDoc.

private ViewModel generateDoc(ProtoFile file, GapicProductConfig productConfig) {
    ModelTypeTable typeTable = new ModelTypeTable(new RubyTypeTable(productConfig.getPackageName()), new RubyModelTypeNameConverter(productConfig.getPackageName()));
    // Use file path for package name to get file-specific package instead of package for the API.
    SurfaceNamer namer = new RubySurfaceNamer(typeTable.getFullNameFor(file));
    String subPath = pathMapper.getOutputPath(file.getFullName(), productConfig);
    String baseFilename = namer.getProtoFileName(file.getSimpleName());
    GrpcDocView.Builder doc = GrpcDocView.newBuilder();
    doc.templateFileName(DOC_TEMPLATE_FILENAME);
    doc.outputPath(subPath + "/doc/" + baseFilename);
    doc.fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer));
    doc.elementDocs(elementDocTransformer.generateElementDocs(typeTable, namer, file));
    doc.modules(generateModuleViews(new ProtoApiModel(file.getModel()), productConfig, namer, isSourceApiInterfaceFile(file) ? file : null, false));
    return doc.build();
}
Also used : RubyTypeTable(com.google.api.codegen.util.ruby.RubyTypeTable) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) GrpcDocView(com.google.api.codegen.viewmodel.GrpcDocView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 15 with ModelTypeTable

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

Aggregations

ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)15 InterfaceModel (com.google.api.codegen.config.InterfaceModel)8 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)8 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)7 ViewModel (com.google.api.codegen.viewmodel.ViewModel)6 ImmutableList (com.google.common.collect.ImmutableList)4 ArrayList (java.util.ArrayList)4 GrpcDocView (com.google.api.codegen.viewmodel.GrpcDocView)3 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)3 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)3 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)2 FeatureConfig (com.google.api.codegen.transformer.FeatureConfig)2 PhpTypeTable (com.google.api.codegen.util.php.PhpTypeTable)2 RubyTypeTable (com.google.api.codegen.util.ruby.RubyTypeTable)2 MockServiceImplView (com.google.api.codegen.viewmodel.testing.MockServiceImplView)2 MockServiceUsageView (com.google.api.codegen.viewmodel.testing.MockServiceUsageView)2 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)1 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)1 DefaultFeatureConfig (com.google.api.codegen.transformer.DefaultFeatureConfig)1 TypeAlias (com.google.api.codegen.util.TypeAlias)1