Search in sources :

Example 1 with GapicInterfaceContext

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

the class CSharpGapicClientTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName(), ALIAS_MODE);
    CSharpFeatureConfig featureConfig = new CSharpFeatureConfig();
    InterfaceModel lastApiInterface = null;
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(productConfig.getPackageName(), ALIAS_MODE), namer, featureConfig);
        surfaceDocs.add(generateApiAndSettingsView(context));
        lastApiInterface = apiInterface;
    }
    GapicInterfaceContext context = GapicInterfaceContext.create(lastApiInterface, productConfig, csharpCommonTransformer.createTypeTable(productConfig.getPackageName(), ALIAS_MODE), namer, featureConfig);
    surfaceDocs.add(generateResourceNamesView(context));
    return surfaceDocs;
}
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) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 2 with GapicInterfaceContext

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

the class CSharpGapicSnippetsTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName(), ALIAS_MODE);
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(namer.getExamplePackageName(), ALIAS_MODE), namer, new CSharpFeatureConfig());
        csharpCommonTransformer.addCommonImports(context);
        context.getImportTypeTable().saveNicknameFor("Google.Protobuf.Bytestring");
        context.getImportTypeTable().saveNicknameFor("System.Linq.__import__");
        surfaceDocs.add(generateSnippets(context));
    }
    return surfaceDocs;
}
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) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 3 with GapicInterfaceContext

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

the class CSharpGapicUnitTestTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName(), ALIAS_MODE);
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(namer.getTestPackageName(), ALIAS_MODE), namer, new CSharpFeatureConfig());
        csharpCommonTransformer.addCommonImports(context);
        ModelTypeTable typeTable = context.getImportTypeTable();
        typeTable.saveNicknameFor("Xunit.FactAttribute");
        typeTable.saveNicknameFor("Moq.Mock");
        if (context.getLongRunningMethods().iterator().hasNext()) {
            typeTable.saveNicknameFor("Google.LongRunning.Operations");
        }
        surfaceDocs.add(generateUnitTest(context));
    }
    return surfaceDocs;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 4 with GapicInterfaceContext

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

the class CSharpApiMethodTransformer method generateApiMethods.

@Override
public List<StaticLangApiMethodView> generateApiMethods(InterfaceContext interfaceContext) {
    Preconditions.checkArgument(interfaceContext instanceof GapicInterfaceContext, "Only applicable for protobuf-based API in CSharp.");
    GapicInterfaceContext context = (GapicInterfaceContext) interfaceContext;
    List<ParamWithSimpleDoc> pagedMethodAdditionalParams = new ImmutableList.Builder<ParamWithSimpleDoc>().addAll(csharpCommonTransformer.pagedMethodAdditionalParams()).addAll(csharpCommonTransformer.callSettingsParam()).build();
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    // gRPC streaming methods.
    for (MethodModel method : csharpCommonTransformer.getSupportedMethods(context)) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        MethodContext requestMethodContext = context.asRequestMethodContext(method);
        if (methodConfig.isGrpcStreaming()) {
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup).withCallingForms(ImmutableList.of(CallingForm.FlattenedStreamingBidi, CallingForm.FlattenedStreamingServer));
                    apiMethods.add(generateGrpcStreamingFlattenedMethod(methodContext, csharpCommonTransformer.callSettingsParam(), null));
                }
            }
            requestMethodContext = requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestStreamingBidi, CallingForm.RequestStreamingServer));
            apiMethods.add(generateGrpcStreamingRequestObjectMethod(requestMethodContext, null));
        } else if (requestMethodContext.isLongRunningMethodContext()) {
            // LRO methods.
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    GapicMethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
                    apiMethods.addAll(generateFlattenedLroMethods(methodContext));
                }
            }
            apiMethods.add(generateAsyncOperationRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.LongRunningRequestAsyncPollUntilComplete)), csharpCommonTransformer.callSettingsParam(), true, null));
            apiMethods.add(generateOperationRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.LongRunningRequestPollUntilComplete)), csharpCommonTransformer.callSettingsParam(), null));
        } else if (methodConfig.isPageStreaming()) {
            // Paged streaming methods.
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
                    apiMethods.addAll(generatePageStreamingFlattenedMethods(methodContext, pagedMethodAdditionalParams));
                }
            }
            apiMethods.add(generatePagedRequestObjectAsyncMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestAsyncPaged, CallingForm.RequestAsyncPagedAll, CallingForm.RequestAsyncPagedPageSize)), csharpCommonTransformer.callSettingsParam(), null));
            apiMethods.add(generatePagedRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestPaged, CallingForm.RequestPagedAll, CallingForm.RequestPagedPageSize)), csharpCommonTransformer.callSettingsParam(), null));
        } else {
            // Unary methods.
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    GapicMethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
                    apiMethods.addAll(generateNormalFlattenedMethods(methodContext));
                }
            }
            apiMethods.add(generateRequestObjectAsyncMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.RequestAsync)), csharpCommonTransformer.callSettingsParam(), ClientMethodType.AsyncRequestObjectCallSettingsMethod, null));
            apiMethods.add(generateRequestObjectAsyncMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.RequestAsync)), csharpCommonTransformer.cancellationTokenParam(), ClientMethodType.AsyncRequestObjectCancellationMethod, null));
            apiMethods.add(generateRequestObjectMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.Request)), csharpCommonTransformer.callSettingsParam(), null));
        }
    }
    return apiMethods;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) MethodContext(com.google.api.codegen.config.MethodContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) ParamWithSimpleDoc(com.google.api.codegen.transformer.ParamWithSimpleDoc) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 5 with GapicInterfaceContext

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

the class GoGapicSurfaceTestTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
    GoSurfaceNamer namer = new GoSurfaceNamer(productConfig.getPackageName());
    List<ViewModel> models = new ArrayList<ViewModel>();
    models.add(generateMockServiceView(model, productConfig, namer));
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        if (interfaceConfig == null || interfaceConfig.getSmokeTestConfig() == null) {
            continue;
        }
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, GoGapicSurfaceTransformer.createTypeTable(), namer, featureConfig);
        models.add(createSmokeTestClassView(context));
    }
    return models;
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) 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)

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