Search in sources :

Example 11 with ImportSectionView

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

the class PhpGapicSurfaceTestTransformer method createUnitTestFileView.

private ClientTestFileView createUnitTestFileView(GapicInterfaceContext context) {
    addUnitTestImports(context.getImportTypeTable());
    String outputPath = PhpGapicCodePathMapper.newBuilder().setPrefix("tests/Unit").build().getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
    SurfaceNamer namer = context.getNamer();
    String name = namer.getUnitTestClassName(context.getInterfaceConfig());
    ClientTestClassView.Builder testClass = ClientTestClassView.newBuilder();
    testClass.apiSettingsClassName(namer.getNotImplementedString("PhpGapicSurfaceTestTransformer.generateTestView - apiSettingsClassName"));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.name(name);
    testClass.apiName(getApiName(context.getProductConfig().getPackageName()));
    testClass.testCases(createTestCaseViews(context));
    // Add gRPC client imports.
    for (InterfaceModel grpcInterface : mockServiceTransformer.getGrpcInterfacesForService(context.getApiModel(), context.getProductConfig(), context.getInterfaceModel()).values()) {
        context.getImportTypeTable().getAndSaveNicknameFor(namer.getGrpcClientTypeName(grpcInterface));
    }
    testClass.mockServices(mockServiceTransformer.createMockServices(context.getNamer(), context.getApiModel(), context.getProductConfig()));
    testClass.missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress());
    testClass.missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes());
    ClientTestFileView.Builder testFile = ClientTestFileView.newBuilder();
    testFile.testClass(testClass.build());
    testFile.outputPath(namer.getSourceFilePath(outputPath, name));
    testFile.templateFileName(UNIT_TEST_TEMPLATE_FILE);
    ImportSectionView importSection = importSectionTransformer.generateImportSection(context.getImportTypeTable().getImports());
    SurfaceNamer testPackageNamer = namer.cloneWithPackageName(namer.getTestPackageName(SurfaceNamer.TestKind.UNIT));
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSection, testPackageNamer);
    testFile.fileHeader(fileHeader);
    return testFile.build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ClientTestClassView(com.google.api.codegen.viewmodel.testing.ClientTestClassView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView) ClientTestFileView(com.google.api.codegen.viewmodel.testing.ClientTestFileView) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 12 with ImportSectionView

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

the class PythonSampleImportTransformer method generateImportSection.

public ImportSectionView generateImportSection(MethodContext context, CallingForm form, OutputContext outputContext, ImportTypeTable initCodeTypeTable, Iterable<InitCodeNode> nodes) {
    ImportSectionView.Builder imports = ImportSectionView.newBuilder();
    ImmutableList.Builder<ImportFileView> appImports = ImmutableList.builder();
    // First get all the imports generated from InitCodeTransformer
    List<ImportFileView> initCodeAppImports = importSectionTransformer.generateImportSection(context, nodes).appImports();
    appImports.addAll(initCodeAppImports);
    // Then add more imports that other parts of the sample need
    // For now we only need to special-case `enums`
    boolean addEnumImports = outputContext.stringFormattedVariableTypes().stream().anyMatch(TypeModel::isEnum) || Streams.stream(nodes).map(InitCodeNode::getType).anyMatch(TypeModel::isEnum);
    if (addEnumImports) {
        ImportTypeView importTypeView = ImportTypeView.newBuilder().fullName("enums").type(ImportType.SimpleImport).nickname("").build();
        ImportFileView enumImportView = ImportFileView.newBuilder().moduleName(context.getNamer().getVersionedDirectoryNamespace()).types(Collections.singletonList(importTypeView)).build();
        if (!initCodeAppImports.contains(enumImportView)) {
            appImports.add(enumImportView);
        }
    }
    return imports.appImports(appImports.build()).build();
}
Also used : ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) InitCodeNode(com.google.api.codegen.metacode.InitCodeNode) ImmutableList(com.google.common.collect.ImmutableList) ImportTypeView(com.google.api.codegen.viewmodel.ImportTypeView) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 13 with ImportSectionView

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

the class GoGapicSurfaceTestTransformer method generateMockServiceView.

private MockCombinedView generateMockServiceView(ApiModel model, GapicProductConfig productConfig, SurfaceNamer namer) {
    ModelTypeTable typeTable = GoGapicSurfaceTransformer.createTypeTable();
    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(apiInterface)).name(namer.getMockGrpcServiceImplName(apiInterface)).grpcMethods(mockServiceTransformer.createMockGrpcMethodViews(context)).build());
    }
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        // We don't need any import here.
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, namer, featureConfig);
        testClasses.add(ClientTestClassView.newBuilder().apiSettingsClassName(namer.getNotImplementedString("GoGapicSurfaceTestTransformer.generateMockServiceView - apiSettingsClassName")).apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig())).name(namer.getNotImplementedString("GoGapicSurfaceTestTransformer.generateMockServiceView - name")).testCases(createTestCaseViews(context)).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockServices(Collections.emptyList()).build());
    }
    ImportSectionView importSection = importSectionTransformer.generateImportSection(typeTable.getImports());
    return MockCombinedView.newBuilder().outputPath(productConfig.getPackageName() + File.separator + "mock_test.go").serviceImpls(impls).testClasses(testClasses).templateFileName(MOCK_SERVICE_TEMPLATE_FILE).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).mockServices(mockServiceTransformer.createMockServices(namer, model, productConfig)).build();
}
Also used : 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.config.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 14 with ImportSectionView

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

the class PythonGapicSurfaceTransformer method generateVersionedInitView.

private ViewModel generateVersionedInitView(ProtoApiModel apiModel, GapicProductConfig productConfig) {
    SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
    boolean packageHasEnums = packageHasEnums(apiModel.getProtoModel());
    ImportSectionView imports = importSectionTransformer.generateVersionedInitImportSection(apiModel, productConfig, namer, packageHasEnums);
    return VersionIndexView.newBuilder().templateFileName(VERSIONED_INIT_TEMPLATE_FILENAME).outputPath(versionedInitOutputFile(namer)).requireViews(versionedInitRequireViews(apiModel, productConfig, namer)).apiVersion(namer.getApiWrapperModuleVersion()).namespace(namer.getVersionedDirectoryNamespace()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, imports, namer)).packageHasEnums(packageHasEnums).build();
}
Also used : SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 15 with ImportSectionView

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

ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)20 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)13 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)9 InterfaceModel (com.google.api.codegen.config.InterfaceModel)8 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)5 ImmutableList (com.google.common.collect.ImmutableList)5 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)4 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)3 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)3 MethodModel (com.google.api.codegen.config.MethodModel)3 InitCodeView (com.google.api.codegen.viewmodel.InitCodeView)3 ViewModel (com.google.api.codegen.viewmodel.ViewModel)3 OutputContext (com.google.api.codegen.config.OutputContext)2 OptionalArrayMethodView (com.google.api.codegen.viewmodel.OptionalArrayMethodView)2 ClientTestFileView (com.google.api.codegen.viewmodel.testing.ClientTestFileView)2 MockServiceImplView (com.google.api.codegen.viewmodel.testing.MockServiceImplView)2 ArrayList (java.util.ArrayList)2 OutputSpec (com.google.api.codegen.OutputSpec)1 SampleValueSet (com.google.api.codegen.SampleValueSet)1 TargetLanguage (com.google.api.codegen.common.TargetLanguage)1