Search in sources :

Example 21 with MethodConfig

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

the class CSharpGapicUnitTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
    ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
    SymbolTable testNameTable = new SymbolTable();
    for (MethodModel method : context.getSupportedMethods()) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        if (methodConfig.isGrpcStreaming()) {
        // TODO: Add support for streaming methods
        } else if (methodConfig.isFlattening()) {
            ClientMethodType clientMethodTypeSync;
            ClientMethodType clientMethodTypeAsync;
            if (methodConfig.isPageStreaming()) {
                // TODO: Add support for page-streaming methods
                continue;
            } else if (methodConfig.isLongRunningOperation()) {
                // TODO: Add support for LRO methods
                continue;
            } else {
                clientMethodTypeSync = ClientMethodType.FlattenedMethod;
                clientMethodTypeAsync = ClientMethodType.FlattenedAsyncCallSettingsMethod;
            }
            if (methodConfig.getRerouteToGrpcInterface() != null) {
                // TODO: Add support for rerouted methods
                continue;
            }
            for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                GapicMethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                testCaseViews.add(createFlattenedTestCase(methodContext, testNameTable, flatteningGroup.getFlattenedFieldConfigs().values(), clientMethodTypeSync, Synchronicity.Sync));
                testCaseViews.add(createFlattenedTestCase(methodContext, testNameTable, flatteningGroup.getFlattenedFieldConfigs().values(), clientMethodTypeAsync, Synchronicity.Async));
            }
            GapicMethodContext requestContext = context.asRequestMethodContext(method);
            testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Sync));
            testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Async));
        } else {
            if (methodConfig.isPageStreaming() || methodConfig.isLongRunningOperation() || methodConfig.getRerouteToGrpcInterface() != null) {
                // TODO: Add support for page-streaming, LRO, and rerouted methods
                continue;
            }
            GapicMethodContext requestContext = context.asRequestMethodContext(method);
            testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Sync));
            testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Async));
        }
    }
    return testCaseViews;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) ArrayList(java.util.ArrayList) SymbolTable(com.google.api.codegen.util.SymbolTable) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 22 with MethodConfig

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

the class JavaSurfaceTestTransformer method createSmokeTestCaseApiMethodView.

private StaticLangApiMethodView createSmokeTestCaseApiMethodView(MethodContext methodContext) {
    MethodConfig methodConfig = methodContext.getMethodConfig();
    StaticLangApiMethodView initialApiMethodView;
    if (methodConfig.isPageStreaming()) {
        if (methodContext.isFlattenedMethodContext()) {
            initialApiMethodView = apiMethodTransformer.generatePagedFlattenedMethod(methodContext);
        } else {
            throw new UnsupportedOperationException("Unsupported smoke test type: page-streaming + request-object");
        }
    } else if (methodConfig.isGrpcStreaming()) {
        throw new UnsupportedOperationException("Unsupported smoke test type: grpc-streaming");
    } else if (methodConfig.isLongRunningOperation()) {
        if (methodContext.isFlattenedMethodContext()) {
            initialApiMethodView = apiMethodTransformer.generateAsyncOperationFlattenedMethod(methodContext);
        } else {
            throw new UnsupportedOperationException("Unsupported smoke test type: long-running + request-object");
        }
    } else {
        if (methodContext.isFlattenedMethodContext()) {
            initialApiMethodView = apiMethodTransformer.generateFlattenedMethod(methodContext);
        } else {
            throw new UnsupportedOperationException("Unsupported smoke test type: simple-call + request-object");
        }
    }
    StaticLangApiMethodView.Builder apiMethodView = initialApiMethodView.toBuilder();
    InitCodeView initCodeView = initCodeTransformer.generateInitCode(methodContext, testCaseTransformer.createSmokeTestInitContext(methodContext));
    apiMethodView.initCode(initCodeView);
    return apiMethodView.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Example 23 with MethodConfig

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

the class JavaSurfaceTransformer method generateApiMethods.

private List<StaticLangApiMethodView> generateApiMethods(InterfaceContext context) {
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    for (MethodModel method : context.getSupportedMethods()) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        MethodContext requestMethodContext = context.asRequestMethodContext(method);
        if (methodConfig.isPageStreaming()) {
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                    apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext));
                    if (hasAnyResourceNameParameter(flatteningGroup)) {
                        apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
                    }
                }
            }
            apiMethods.add(apiMethodTransformer.generatePagedRequestObjectMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generatePagedCallableMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generateUnpagedListCallableMethod(requestMethodContext));
        } else if (methodConfig.isGrpcStreaming()) {
            ImportTypeTable typeTable = context.getImportTypeTable();
            switch(methodConfig.getGrpcStreamingType()) {
                case BidiStreaming:
                    typeTable.saveNicknameFor("com.google.api.gax.rpc.BidiStreamingCallable");
                    break;
                case ClientStreaming:
                    typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientStreamingCallable");
                    break;
                case ServerStreaming:
                    typeTable.saveNicknameFor("com.google.api.gax.rpc.ServerStreamingCallable");
                    break;
                default:
                    throw new IllegalArgumentException("Invalid streaming type: " + methodConfig.getGrpcStreamingType());
            }
            apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
        } else if (methodConfig.isLongRunningOperation()) {
            context.getImportTypeTable().saveNicknameFor("com.google.api.gax.rpc.OperationCallable");
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                    apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(flattenedMethodContext));
                    if (hasAnyResourceNameParameter(flatteningGroup)) {
                        apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
                    }
                }
            }
            apiMethods.add(apiMethodTransformer.generateAsyncOperationRequestObjectMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generateOperationCallableMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
        } else {
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                    apiMethods.add(apiMethodTransformer.generateFlattenedMethod(flattenedMethodContext));
                    if (hasAnyResourceNameParameter(flatteningGroup)) {
                        apiMethods.add(apiMethodTransformer.generateFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
                    }
                }
            }
            apiMethods.add(apiMethodTransformer.generateRequestObjectMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
        }
    }
    return apiMethods;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) ArrayList(java.util.ArrayList) MethodContext(com.google.api.codegen.transformer.MethodContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 24 with MethodConfig

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

the class PhpApiMethodParamTransformer method getMethodParamDocs.

private List<ParamDocView> getMethodParamDocs(GapicMethodContext context, Iterable<FieldModel> fields) {
    if (context.getMethodModel().getRequestStreaming()) {
        return ImmutableList.of();
    }
    MethodConfig methodConfig = context.getMethodConfig();
    ImmutableList.Builder<ParamDocView> paramDocs = ImmutableList.builder();
    for (FieldModel field : fields) {
        SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
        paramDoc.paramName(context.getNamer().getVariableName(field));
        paramDoc.typeName(context.getTypeTable().getAndSaveNicknameFor(field));
        ImmutableList.Builder<String> docLines = ImmutableList.builder();
        if (methodConfig.isPageStreaming() && methodConfig.getPageStreaming().hasPageSizeField() && field.equals(methodConfig.getPageStreaming().getPageSizeField())) {
            docLines.add("The maximum number of resources contained in the underlying API", "response. The API may return fewer values in a page, even if", "there are additional values to be retrieved.");
        } else if (methodConfig.isPageStreaming() && field.equals(methodConfig.getPageStreaming().getRequestTokenField())) {
            docLines.add("A page token is used to specify a page of values to be returned.", "If no page token is specified (the default), the first page", "of values will be returned. Any page token used here must have", "been generated by a previous call to the API.");
        } else {
            docLines.addAll(context.getNamer().getDocLines(field));
        }
        if (field.isEnum()) {
            // For enums, we alter the param type to int, and document where to find the relevant
            // const values
            String typeNameSingular = context.getTypeTable().getFullNameFor(field.getType().makeOptional());
            if (field.isRepeated()) {
                paramDoc.typeName("int[]");
            } else {
                paramDoc.typeName("int");
            }
            docLines.add("For allowed values, use constants defined on {@see " + typeNameSingular + "}");
        }
        paramDoc.lines(docLines.build());
        paramDocs.add(paramDoc.build());
    }
    return paramDocs.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ImmutableList(com.google.common.collect.ImmutableList) MapParamDocView(com.google.api.codegen.viewmodel.MapParamDocView) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) FieldModel(com.google.api.codegen.config.FieldModel)

Example 25 with MethodConfig

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

the class PhpGapicSurfaceTransformer method generateRestInterfaceConfigViews.

private List<RestInterfaceConfigView> generateRestInterfaceConfigViews(GapicInterfaceContext context) {
    List<RestInterfaceConfigView> configViews = new ArrayList<>();
    GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
    SurfaceNamer namer = context.getNamer();
    Map<String, List<HttpRule>> interfaces = new TreeMap<>();
    Service serviceConfig = serviceModel.getServiceConfig();
    for (MethodModel methodModel : context.getSupportedMethods()) {
        GapicMethodContext methodContext = context.asDynamicMethodContext(methodModel);
        MethodConfig methodConfig = methodContext.getMethodConfig();
        Method method = methodContext.getMethod();
        // REST does not support streaming methods
        if (methodConfig.isGrpcStreaming()) {
            continue;
        }
        String interfaceName = methodConfig.getRerouteToGrpcInterface() == null ? context.getInterface().getFullName() : methodConfig.getRerouteToGrpcInterface();
        HttpRule httpRule = getHttpRule(method.getOptionFields()).toBuilder().setSelector(String.format("%s.%s", interfaceName, method.getSimpleName())).build();
        addHttpRuleToMap(interfaces, interfaceName, httpRule);
    }
    for (HttpRule httpRule : serviceConfig.getHttp().getRulesList()) {
        String selector = httpRule.getSelector();
        String interfaceName = selector.substring(0, selector.lastIndexOf("."));
        addHttpRuleToMap(interfaces, interfaceName, httpRule);
    }
    for (Map.Entry<String, List<HttpRule>> entry : interfaces.entrySet()) {
        configViews.add(generateRestInterfaceConfigView(entry.getKey(), entry.getValue(), namer));
    }
    return configViews;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) RestInterfaceConfigView(com.google.api.codegen.viewmodel.RestInterfaceConfigView) ArrayList(java.util.ArrayList) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) Service(com.google.api.Service) Method(com.google.api.tools.framework.model.Method) TreeMap(java.util.TreeMap) HttpRule(com.google.api.HttpRule) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TreeMap(java.util.TreeMap) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

MethodConfig (com.google.api.codegen.config.MethodConfig)51 MethodModel (com.google.api.codegen.config.MethodModel)29 ArrayList (java.util.ArrayList)20 ImmutableList (com.google.common.collect.ImmutableList)14 FieldModel (com.google.api.codegen.config.FieldModel)13 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)9 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)8 MethodContext (com.google.api.codegen.transformer.MethodContext)8 FieldConfig (com.google.api.codegen.config.FieldConfig)7 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)6 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)6 SimpleParamDocView (com.google.api.codegen.viewmodel.SimpleParamDocView)6 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)6 ParamDocView (com.google.api.codegen.viewmodel.ParamDocView)5 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)4 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)3 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)3 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)3 ParamWithSimpleDoc (com.google.api.codegen.transformer.ParamWithSimpleDoc)3 SymbolTable (com.google.api.codegen.util.SymbolTable)3