Search in sources :

Example 26 with GapicInterfaceContext

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

the class PhpGapicSurfaceTestTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> views = new ArrayList<>();
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig, PhpSurfaceNamer.TestKind.UNIT);
        views.add(createUnitTestFileView(context));
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            context = createContext(apiInterface, productConfig, PhpSurfaceNamer.TestKind.SYSTEM);
            views.add(createSmokeTestClassView(context));
        }
    }
    return views;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 27 with GapicInterfaceContext

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

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

Example 29 with GapicInterfaceContext

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

the class CSharpGapicClientTransformer method generateApiClass.

private StaticLangApiView generateApiClass(GapicInterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    StaticLangApiView.Builder apiClass = StaticLangApiView.newBuilder();
    List<StaticLangApiMethodView> methods = apiMethodTransformer.generateApiMethods(context);
    apiClass.doc(serviceTransformer.generateServiceDoc(context, null, context.getProductConfig()));
    apiClass.name(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    apiClass.implName(namer.getApiWrapperClassImplName(context.getInterfaceConfig()));
    apiClass.grpcServiceName(namer.getGrpcContainerTypeName(context.getInterfaceModel()));
    String grpcTypeName = namer.getGrpcServiceClassName(context.getInterfaceModel());
    int dotIndex = grpcTypeName.indexOf('.');
    apiClass.grpcTypeNameOuter(grpcTypeName.substring(0, dotIndex));
    apiClass.grpcTypeNameInner(grpcTypeName.substring(dotIndex + 1, grpcTypeName.length()));
    apiClass.settingsClassName(context.getNamer().getApiSettingsClassName(context.getInterfaceConfig()));
    List<ApiCallableView> callables = new ArrayList<>();
    for (ApiCallableView call : apiCallableTransformer.generateStaticLangApiCallables(context)) {
        if (call.type() == ApiCallableImplType.SimpleApiCallable || call.type() == ApiCallableImplType.BatchingApiCallable || call.type() == ApiCallableImplType.BidiStreamingApiCallable || call.type() == ApiCallableImplType.ServerStreamingApiCallable) {
            callables.add(call);
        }
    }
    apiClass.apiCallableMembers(callables);
    apiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
    apiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
    apiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
    apiClass.apiMethods(methods);
    List<StaticLangApiMethodView> methodsImpl = new ArrayList<>();
    for (StaticLangApiMethodView method : methods) {
        if (methodTypeHasImpl(method.type())) {
            methodsImpl.add(method);
        }
    }
    apiClass.apiMethodsImpl(methodsImpl);
    apiClass.hasDefaultInstance(context.getInterfaceConfig().hasDefaultInstance());
    apiClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
    apiClass.reroutedGrpcClients(csharpCommonTransformer.generateReroutedGrpcView(context));
    apiClass.modifyMethods(generateModifyMethods(context));
    apiClass.apiHasUnaryMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.NonStreaming));
    apiClass.apiHasServerStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.ServerStreaming));
    apiClass.apiHasClientStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.ClientStreaming));
    apiClass.apiHasBidiStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.BidiStreaming));
    return apiClass.build();
}
Also used : Arrays(java.util.Arrays) ListMultimap(com.google.common.collect.ListMultimap) RetryCodesDefinitionView(com.google.api.codegen.viewmodel.RetryCodesDefinitionView) ApiCallableView(com.google.api.codegen.viewmodel.ApiCallableView) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) StaticLangApiMethodTransformer(com.google.api.codegen.transformer.StaticLangApiMethodTransformer) MethodContext(com.google.api.codegen.config.MethodContext) BatchingTransformer(com.google.api.codegen.transformer.BatchingTransformer) ViewModel(com.google.api.codegen.viewmodel.ViewModel) Map(java.util.Map) ResourceProtoFieldView(com.google.api.codegen.viewmodel.ResourceProtoFieldView) ApiCallSettingsView(com.google.api.codegen.viewmodel.ApiCallSettingsView) ResourceNameType(com.google.api.codegen.config.ResourceNameType) ResourceProtoView(com.google.api.codegen.viewmodel.ResourceProtoView) CSharpTypeTable(com.google.api.codegen.util.csharp.CSharpTypeTable) GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) ResourceNameView(com.google.api.codegen.viewmodel.ResourceNameView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) Collection(java.util.Collection) Set(java.util.Set) FileHeaderTransformer(com.google.api.codegen.transformer.FileHeaderTransformer) Collectors(java.util.stream.Collectors) Name(com.google.api.codegen.util.Name) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) List(java.util.List) ApiCallableTransformer(com.google.api.codegen.transformer.ApiCallableTransformer) InterfaceModel(com.google.api.codegen.config.InterfaceModel) SettingsDocView(com.google.api.codegen.viewmodel.SettingsDocView) Entry(java.util.Map.Entry) ModelToViewTransformer(com.google.api.codegen.transformer.ModelToViewTransformer) ResourceNameSingleView(com.google.api.codegen.viewmodel.ResourceNameSingleView) ApiCallableImplType(com.google.api.codegen.viewmodel.ApiCallableImplType) StandardImportSectionTransformer(com.google.api.codegen.transformer.StandardImportSectionTransformer) FieldModel(com.google.api.codegen.config.FieldModel) GrpcStreamingType(com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType) PageStreamingTransformer(com.google.api.codegen.transformer.PageStreamingTransformer) ServiceTransformer(com.google.api.codegen.transformer.ServiceTransformer) PathTemplateTransformer(com.google.api.codegen.transformer.PathTemplateTransformer) StaticLangApiAndSettingsFileView(com.google.api.codegen.viewmodel.StaticLangApiAndSettingsFileView) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MethodModel(com.google.api.codegen.config.MethodModel) MethodConfig(com.google.api.codegen.config.MethodConfig) CSharpAliasMode(com.google.api.codegen.util.csharp.CSharpAliasMode) StaticLangSettingsView(com.google.api.codegen.viewmodel.StaticLangSettingsView) ResourceNameMessageConfigs(com.google.api.codegen.config.ResourceNameMessageConfigs) ResourceNameConfig(com.google.api.codegen.config.ResourceNameConfig) File(java.io.File) StaticLangResourceNamesView(com.google.api.codegen.viewmodel.StaticLangResourceNamesView) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) ApiModel(com.google.api.codegen.config.ApiModel) ProductServiceConfig(com.google.api.codegen.config.ProductServiceConfig) RetryDefinitionsTransformer(com.google.api.codegen.transformer.RetryDefinitionsTransformer) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) Comparator(java.util.Comparator) Collections(java.util.Collections) ModifyMethodView(com.google.api.codegen.viewmodel.ModifyMethodView) FieldConfig(com.google.api.codegen.config.FieldConfig) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) ApiCallableView(com.google.api.codegen.viewmodel.ApiCallableView) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ArrayList(java.util.ArrayList) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView)

Example 30 with GapicInterfaceContext

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

the class GoGapicSurfaceTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> models = new ArrayList<>();
    GoSurfaceNamer namer = new GoSurfaceNamer(productConfig.getPackageName());
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(), namer, featureConfig);
        models.add(generate(context));
        context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(), namer, featureConfig);
        models.add(generateExample(context));
    }
    models.add(generatePackageInfo(model, productConfig, namer));
    return models;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) ArrayList(java.util.ArrayList) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Aggregations

GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)32 InterfaceModel (com.google.api.codegen.config.InterfaceModel)28 ViewModel (com.google.api.codegen.viewmodel.ViewModel)20 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)15 ImmutableList (com.google.common.collect.ImmutableList)15 ArrayList (java.util.ArrayList)15 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)10 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)9 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)9 MethodModel (com.google.api.codegen.config.MethodModel)6 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)5 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)5 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)5 HashSet (java.util.HashSet)4 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)3 ApiModel (com.google.api.codegen.config.ApiModel)2 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)2 MethodConfig (com.google.api.codegen.config.MethodConfig)2 MethodContext (com.google.api.codegen.config.MethodContext)2 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)2