Search in sources :

Example 11 with MethodConfig

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

the class StaticLangApiMethodTransformer method getMethodParamDocs.

private List<ParamDocView> getMethodParamDocs(MethodContext context, Iterable<FieldConfig> fieldConfigs, List<ParamWithSimpleDoc> additionalParamDocs) {
    MethodModel method = context.getMethodModel();
    List<ParamDocView> allDocs = new ArrayList<>();
    if (method.getRequestStreaming()) {
        allDocs.addAll(ParamWithSimpleDoc.asParamDocViews(additionalParamDocs));
        return allDocs;
    }
    for (FieldConfig fieldConfig : fieldConfigs) {
        FieldModel field = fieldConfig.getField();
        SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
        paramDoc.paramName(context.getNamer().getVariableName(field));
        paramDoc.typeName(context.getTypeTable().getAndSaveNicknameFor(field));
        List<String> docLines = null;
        MethodConfig methodConfig = context.getMethodConfig();
        if (methodConfig.isPageStreaming() && methodConfig.getPageStreaming().hasPageSizeField() && field.equals(methodConfig.getPageStreaming().getPageSizeField())) {
            docLines = Arrays.asList(new String[] { "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 = Arrays.asList(new String[] { "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 = context.getNamer().getDocLines(field);
        }
        paramDoc.lines(docLines);
        allDocs.add(paramDoc.build());
    }
    allDocs.addAll(ParamWithSimpleDoc.asParamDocViews(additionalParamDocs));
    return allDocs;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) FieldModel(com.google.api.codegen.config.FieldModel)

Example 12 with MethodConfig

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

the class StaticLangApiMethodTransformer method setCallableMethodFields.

private void setCallableMethodFields(MethodContext context, String callableName, Builder methodViewBuilder) {
    MethodModel method = context.getMethodModel();
    methodViewBuilder.doc(ApiMethodDocView.newBuilder().mainDocLines(context.getNamer().getDocLines(method, context.getMethodConfig())).paramDocs(new ArrayList<ParamDocView>()).throwsDocLines(new ArrayList<String>()).build());
    methodViewBuilder.initCode(initCodeTransformer.generateInitCode(context.cloneWithEmptyTypeTable(), createInitCodeContext(context, context.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject)));
    methodViewBuilder.methodParams(new ArrayList<RequestObjectParamView>());
    methodViewBuilder.requestObjectParams(new ArrayList<RequestObjectParamView>());
    methodViewBuilder.pathTemplateChecks(new ArrayList<PathTemplateCheckView>());
    String genericAwareResponseTypeFullName = context.getNamer().getGenericAwareResponseTypeName(context);
    String genericAwareResponseType = context.getTypeTable().getAndSaveNicknameFor(genericAwareResponseTypeFullName);
    MethodConfig methodConfig = context.getMethodConfig();
    ApiCallableImplType callableImplType = ApiCallableImplType.SimpleApiCallable;
    if (methodConfig.isGrpcStreaming()) {
        callableImplType = ApiCallableImplType.of(methodConfig.getGrpcStreamingType());
    } else if (methodConfig.isBatching()) {
        callableImplType = ApiCallableImplType.BatchingApiCallable;
    }
    methodViewBuilder.callableMethod(CallableMethodDetailView.newBuilder().genericAwareResponseType(genericAwareResponseType).callableName(callableName).interfaceTypeName(context.getNamer().getApiCallableTypeName(callableImplType.serviceMethodType())).build());
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) PathTemplateCheckView(com.google.api.codegen.viewmodel.PathTemplateCheckView) ArrayList(java.util.ArrayList) ApiCallableImplType(com.google.api.codegen.viewmodel.ApiCallableImplType) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView)

Example 13 with MethodConfig

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

the class GapicContext method getSupportedMethodsV2.

/**
 * Returns a list of RPC methods supported by the context, taking into account GRPC interface
 * rerouting. TODO replace getSupportedMethods with this when all languages are migrated.
 */
public List<Method> getSupportedMethodsV2(Interface apiInterface) {
    GapicInterfaceConfig interfaceConfig = getApiConfig().getInterfaceConfig(apiInterface);
    if (interfaceConfig == null) {
        throw new IllegalStateException("Service not configured in GAPIC config: " + apiInterface.getFullName());
    }
    List<Method> methods = new ArrayList<>(interfaceConfig.getMethodConfigs().size());
    for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) {
        Method method = ((GapicMethodConfig) methodConfig).getMethod();
        if (isSupported(method)) {
            methods.add(method);
        }
    }
    return methods;
}
Also used : GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) ArrayList(java.util.ArrayList) Method(com.google.api.tools.framework.model.Method)

Example 14 with MethodConfig

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

the class TestCaseTransformer method createTestCaseView.

public TestCaseView createTestCaseView(MethodContext methodContext, SymbolTable testNameTable, InitCodeContext initCodeContext, ClientMethodType clientMethodType, Synchronicity synchronicity, InitCodeContext requestObjectInitCodeContext) {
    MethodModel method = methodContext.getMethodModel();
    MethodConfig methodConfig = methodContext.getMethodConfig();
    SurfaceNamer namer = methodContext.getNamer();
    ImportTypeTable typeTable = methodContext.getTypeTable();
    String clientMethodName;
    String responseTypeName;
    String callerResponseTypeName;
    String fullyQualifiedResponseTypeName = methodContext.getMethodModel().getOutputTypeName(typeTable).getFullName();
    if (methodConfig.isPageStreaming()) {
        clientMethodName = namer.getApiMethodName(method, methodConfig.getVisibility());
        responseTypeName = namer.getAndSavePagedResponseTypeName(methodContext, methodConfig.getPageStreaming().getResourcesFieldConfig());
        callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, methodConfig.getPageStreaming().getResourcesFieldConfig());
    } else if (methodConfig.isLongRunningOperation()) {
        clientMethodName = namer.getLroApiMethodName(method, methodConfig.getVisibility());
        responseTypeName = methodContext.getTypeTable().getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getReturnType());
        callerResponseTypeName = responseTypeName;
        fullyQualifiedResponseTypeName = methodContext.getTypeTable().getFullNameFor(methodConfig.getLongRunningConfig().getReturnType());
    } else if (clientMethodType == ClientMethodType.CallableMethod) {
        clientMethodName = namer.getCallableMethodName(method);
        responseTypeName = method.getAndSaveResponseTypeName(typeTable, namer);
        callerResponseTypeName = responseTypeName;
    } else {
        clientMethodName = synchronicity == Synchronicity.Sync ? namer.getApiMethodName(method, methodConfig.getVisibility()) : namer.getAsyncApiMethodName(method, methodConfig.getVisibility());
        responseTypeName = method.getAndSaveResponseTypeName(typeTable, namer);
        callerResponseTypeName = responseTypeName;
    }
    InitCodeView initCode = initCodeTransformer.generateInitCode(methodContext, initCodeContext);
    InitCodeView requestObjectInitCode = requestObjectInitCodeContext != null ? initCodeTransformer.generateInitCode(methodContext, requestObjectInitCodeContext) : null;
    boolean hasRequestParameters = initCode.lines().size() > 0;
    boolean hasReturnValue = !method.isOutputTypeEmpty();
    if (methodConfig.isLongRunningOperation()) {
        hasReturnValue = !methodConfig.getLongRunningConfig().getReturnType().isEmptyType();
    }
    InitCodeContext responseInitCodeContext = createResponseInitCodeContext(methodContext, initCodeContext.symbolTable());
    MockRpcResponseView mockRpcResponseView = createMockResponseView(methodContext, responseInitCodeContext);
    GrpcStreamingView grpcStreamingView = null;
    if (methodConfig.isGrpcStreaming()) {
        String resourceTypeName = null;
        String resourcesFieldGetterName = null;
        if (methodConfig.getGrpcStreaming().hasResourceField()) {
            FieldModel resourcesField = methodConfig.getGrpcStreaming().getResourcesField();
            resourceTypeName = methodContext.getTypeTable().getAndSaveNicknameForElementType(resourcesField);
            resourcesFieldGetterName = namer.getFieldGetFunctionName(resourcesField, Name.from(resourcesField.getSimpleName()));
        }
        grpcStreamingView = GrpcStreamingView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterName(resourcesFieldGetterName).requestInitCodeList(createGrpcStreamingInitCodeViews(methodContext, initCodeContext, initCode)).responseInitCodeList(createGrpcStreamingInitCodeViews(methodContext, responseInitCodeContext, mockRpcResponseView.initCode())).build();
    }
    return TestCaseView.newBuilder().asserts(initCodeTransformer.generateRequestAssertViews(methodContext, initCodeContext)).clientMethodType(clientMethodType).grpcStreamingType(methodConfig.getGrpcStreamingType()).hasRequestParameters(hasRequestParameters).hasReturnValue(hasReturnValue).initCode(initCode).requestObjectInitCode(requestObjectInitCode).mockResponse(mockRpcResponseView).mockServiceVarName(namer.getMockServiceVarName(methodContext.getTargetInterface())).name(synchronicity == Synchronicity.Sync ? namer.getTestCaseName(testNameTable, method) : namer.getAsyncTestCaseName(testNameTable, method)).nameWithException(namer.getExceptionTestCaseName(testNameTable, method)).pageStreamingResponseViews(createPageStreamingResponseViews(methodContext)).grpcStreamingView(grpcStreamingView).requestTypeName(method.getAndSaveRequestTypeName(typeTable, namer)).responseTypeName(responseTypeName).callerResponseTypeName(callerResponseTypeName).fullyQualifiedRequestTypeName(method.getInputTypeName(typeTable).getFullName()).fullyQualifiedResponseTypeName(fullyQualifiedResponseTypeName).serviceConstructorName(namer.getApiWrapperClassConstructorName(methodContext.getInterfaceConfig())).fullyQualifiedServiceClassName(namer.getFullyQualifiedApiWrapperClassName(methodContext.getInterfaceConfig())).fullyQualifiedAliasedServiceClassName(namer.getTopLevelAliasedApiClassName((methodContext.getInterfaceConfig()), packageHasMultipleServices)).clientMethodName(clientMethodName).mockGrpcStubTypeName(namer.getMockGrpcServiceImplName(methodContext.getTargetInterface())).createStubFunctionName(namer.getCreateStubFunctionName(methodContext.getTargetInterface())).grpcStubCallString(namer.getGrpcStubCallString(methodContext.getTargetInterface(), method)).clientHasDefaultInstance(methodContext.getInterfaceConfig().hasDefaultInstance()).methodDescriptor(getMethodDescriptorName(methodContext)).grpcMethodName(synchronicity == Synchronicity.Sync ? namer.getGrpcMethodName(method) : namer.getAsyncGrpcMethodName(method)).build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) MockRpcResponseView(com.google.api.codegen.viewmodel.testing.MockRpcResponseView) GrpcStreamingView(com.google.api.codegen.viewmodel.testing.GrpcStreamingView) FieldModel(com.google.api.codegen.config.FieldModel) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Example 15 with MethodConfig

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

the class TestCaseTransformer method createPageStreamingResponseViews.

private List<PageStreamingResponseView> createPageStreamingResponseViews(MethodContext methodContext) {
    MethodConfig methodConfig = methodContext.getMethodConfig();
    SurfaceNamer namer = methodContext.getNamer();
    List<PageStreamingResponseView> pageStreamingResponseViews = new ArrayList<>();
    if (!methodConfig.isPageStreaming()) {
        return pageStreamingResponseViews;
    }
    FieldConfig resourcesFieldConfig = methodConfig.getPageStreaming().getResourcesFieldConfig();
    FieldModel resourcesField = resourcesFieldConfig.getField();
    String resourceTypeName = methodContext.getTypeTable().getAndSaveNicknameForElementType(resourcesField);
    // Construct the list of function calls needed to retrieve paged resource from response object.
    ImmutableList.Builder<String> resourcesFieldGetFunctionList = new ImmutableList.Builder<>();
    for (FieldModel field : resourcesFieldConfig.getFieldPath()) {
        resourcesFieldGetFunctionList.add(namer.getFieldGetFunctionName(field));
    }
    pageStreamingResponseViews.add(PageStreamingResponseView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterNames(resourcesFieldGetFunctionList.build()).resourcesIterateMethod(namer.getPagedResponseIterateMethod()).resourcesVarName(namer.localVarName(Name.from("resources"))).build());
    if (methodContext.getFeatureConfig().useResourceNameFormatOption(resourcesFieldConfig)) {
        resourceTypeName = methodContext.getNamer().getAndSaveElementResourceTypeName(methodContext.getTypeTable(), resourcesFieldConfig);
        resourcesFieldGetFunctionList = new ImmutableList.Builder<>();
        for (FieldModel field : resourcesFieldConfig.getFieldPath()) {
            resourcesFieldGetFunctionList.add(namer.getFieldGetFunctionName(methodContext.getFeatureConfig(), resourcesFieldConfig));
        }
        String expectedTransformFunction = null;
        if (methodContext.getFeatureConfig().useResourceNameConverters(resourcesFieldConfig)) {
            expectedTransformFunction = namer.getResourceTypeParseMethodName(methodContext.getTypeTable(), resourcesFieldConfig);
        }
        pageStreamingResponseViews.add(PageStreamingResponseView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterNames(resourcesFieldGetFunctionList.build()).resourcesIterateMethod(namer.getPagedResponseIterateMethod(methodContext.getFeatureConfig(), resourcesFieldConfig)).expectedValueTransformFunction(expectedTransformFunction).resourcesVarName(namer.localVarName(Name.from("resource_names"))).build());
    }
    return pageStreamingResponseViews;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) InitFieldConfig(com.google.api.codegen.metacode.InitFieldConfig) FieldConfig(com.google.api.codegen.config.FieldConfig) ImmutableList(com.google.common.collect.ImmutableList) PageStreamingResponseView(com.google.api.codegen.viewmodel.testing.PageStreamingResponseView) ArrayList(java.util.ArrayList) FieldModel(com.google.api.codegen.config.FieldModel)

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