Search in sources :

Example 46 with MethodConfig

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

the class JavaSurfaceTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(InterfaceContext context) {
    ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
    SymbolTable testNameTable = new SymbolTable();
    for (MethodModel method : context.getSupportedMethods()) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        if (methodConfig.isGrpcStreaming()) {
            if (methodConfig.getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
                // Issue: https://github.com/googleapis/toolkit/issues/946
                continue;
            }
            addGrpcStreamingTestImports(context, methodConfig.getGrpcStreamingType());
            MethodContext methodContext = context.asRequestMethodContext(method);
            InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), methodConfig.getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
            testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, ClientMethodType.CallableMethod));
        } else if (methodConfig.isFlattening()) {
            ClientMethodType clientMethodType;
            if (methodConfig.isPageStreaming()) {
                clientMethodType = ClientMethodType.PagedFlattenedMethod;
            } else if (methodConfig.isLongRunningOperation()) {
                clientMethodType = ClientMethodType.AsyncOperationFlattenedMethod;
            } else {
                clientMethodType = ClientMethodType.FlattenedMethod;
            }
            for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                MethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), flatteningGroup.getFlattenedFieldConfigs().values(), InitCodeOutputType.FieldList, valueGenerator);
                testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
            }
        } else {
            // TODO: Add support of non-flattening method
            // Github issue: https://github.com/googleapis/toolkit/issues/393
            System.err.println("Non-flattening method test is not supported yet for " + method.getSimpleName());
        }
    }
    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) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) ArrayList(java.util.ArrayList) SymbolTable(com.google.api.codegen.util.SymbolTable) MethodContext(com.google.api.codegen.transformer.MethodContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext)

Example 47 with MethodConfig

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

the class NodeJSApiMethodParamTransformer method generateRequestObjectParamDoc.

private ParamDocView generateRequestObjectParamDoc(GapicMethodContext context) {
    MethodConfig methodConfig = context.getMethodConfig();
    SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
    paramDoc.lines(ImmutableList.of("The request object that will be sent."));
    String paramName = context.getNamer().localVarName(Name.from("request"));
    Iterable<FieldModel> optionalParams = removePageTokenFromFields(methodConfig);
    if (!methodConfig.getRequiredFieldConfigs().iterator().hasNext() && !optionalParams.iterator().hasNext()) {
        paramName = String.format("[%s]", paramName);
    }
    paramDoc.paramName(paramName);
    paramDoc.typeName("Object");
    return paramDoc.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) FieldModel(com.google.api.codegen.config.FieldModel)

Example 48 with MethodConfig

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

the class NodeJSApiMethodParamTransformer method generateMethodParamDocs.

private List<ParamDocView> generateMethodParamDocs(GapicMethodContext context, Iterable<FieldModel> fields, boolean isOptional) {
    SurfaceNamer namer = context.getNamer();
    MethodConfig methodConfig = context.getMethodConfig();
    ImmutableList.Builder<ParamDocView> docs = ImmutableList.builder();
    for (FieldModel field : fields) {
        if (isRequestTokenParam(methodConfig, field)) {
            continue;
        }
        SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
        String paramName = "request." + namer.getVariableName(field);
        if (isOptional) {
            paramName = String.format("[%s]", paramName);
        }
        paramDoc.paramName(paramName);
        String typeName = namer.getParamTypeName(context.getTypeTable(), field.getType());
        paramDoc.typeName(typeName);
        List<String> fieldDocLines = namer.getDocLines(field);
        ImmutableList.Builder<String> docLines = ImmutableList.builder();
        if (isPageSizeParam(methodConfig, field)) {
            docLines.add("The maximum number of resources contained in the underlying API", "response. If page streaming is performed per-resource, this", "parameter does not affect the return value. If page streaming is", "performed per-page, this determines the maximum number of", "resources in a page.");
        } else {
            docLines.addAll(fieldDocLines);
        }
        paramDoc.lines(docLines.build());
        docs.add(paramDoc.build());
    }
    return docs.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ImmutableList(com.google.common.collect.ImmutableList) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) FieldModel(com.google.api.codegen.config.FieldModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 49 with MethodConfig

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

the class PhpSurfaceNamer method getDynamicLangReturnTypeName.

@Override
public String getDynamicLangReturnTypeName(MethodContext methodContext) {
    MethodModel method = methodContext.getMethodModel();
    MethodConfig methodConfig = methodContext.getMethodConfig();
    if (method.isOutputTypeEmpty()) {
        return "";
    }
    if (methodConfig.isPageStreaming()) {
        return "\\Google\\ApiCore\\PagedListResponse";
    }
    if (methodConfig.isLongRunningOperation()) {
        return "\\Google\\ApiCore\\OperationResponse";
    }
    switch(methodConfig.getGrpcStreamingType()) {
        case NonStreaming:
            return method.getOutputTypeName(methodContext.getTypeTable()).getFullName();
        case BidiStreaming:
            return "\\Google\\ApiCore\\BidiStream";
        case ClientStreaming:
            return "\\Google\\ApiCore\\ClientStream";
        case ServerStreaming:
            return "\\Google\\ApiCore\\ServerStream";
        default:
            return getNotImplementedString("SurfaceNamer.getDynamicReturnTypeName grpcStreamingType:" + methodConfig.getGrpcStreamingType().toString());
    }
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel)

Example 50 with MethodConfig

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

the class PythonApiMethodParamTransformer method generateMethodParamDocs.

private List<ParamDocView> generateMethodParamDocs(GapicMethodContext context, Iterable<FieldModel> fields) {
    SurfaceNamer namer = context.getNamer();
    MethodConfig methodConfig = context.getMethodConfig();
    ImmutableList.Builder<ParamDocView> docs = ImmutableList.builder();
    for (FieldModel field : fields) {
        if (isRequestTokenParam(methodConfig, field)) {
            continue;
        }
        SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
        paramDoc.paramName(namer.getVariableName(field));
        paramDoc.typeName(namer.getParamTypeName(context.getTypeTable(), field.getType()));
        ImmutableList.Builder<String> docLines = ImmutableList.builder();
        if (isPageSizeParam(methodConfig, field)) {
            docLines.add("The maximum number of resources contained in the", "underlying API response. If page streaming is performed per-", "resource, this parameter does not affect the return value. If page", "streaming is performed per-page, this determines the maximum number", "of resources in a page.");
        } else {
            docLines.addAll(namer.getDocLines(field));
            boolean isMessageField = field.isMessage() && !field.isMap();
            boolean isMapContainingMessage = field.isMap() && field.getMapValueField().isMessage();
            if (isMessageField || isMapContainingMessage) {
                String messageType;
                if (isMapContainingMessage) {
                    messageType = context.getTypeTable().getFullNameForElementType(field.getMapValueField());
                } else {
                    messageType = context.getTypeTable().getFullNameForElementType(field);
                }
                docLines.add("If a dict is provided, it must be of the same form as the protobuf", String.format("message :class:`%s`", PythonDocstringUtil.napoleonType(messageType, namer.getVersionedDirectoryNamespace())));
            }
        }
        paramDoc.lines(docLines.build());
        docs.add(paramDoc.build());
    }
    return docs.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ImmutableList(com.google.common.collect.ImmutableList) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) FieldModel(com.google.api.codegen.config.FieldModel) 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