Search in sources :

Example 6 with MethodModel

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

the class DynamicLangApiMethodTransformer method generateMethodDoc.

private ApiMethodDocView generateMethodDoc(GapicMethodContext context) {
    ApiMethodDocView.Builder docBuilder = ApiMethodDocView.newBuilder();
    SurfaceNamer surfaceNamer = context.getNamer();
    MethodModel method = context.getMethodModel();
    MethodConfig methodConfig = context.getMethodConfig();
    docBuilder.mainDocLines(surfaceNamer.getDocLines(method, methodConfig));
    docBuilder.paramDocs(apiMethodParamTransformer.generateParamDocs(context));
    docBuilder.returnTypeName(surfaceNamer.getDynamicLangReturnTypeName(context));
    docBuilder.returnsDocLines(surfaceNamer.getReturnDocLines(context.getSurfaceInterfaceContext(), context, Synchronicity.Sync));
    if (methodConfig.isPageStreaming()) {
        docBuilder.pageStreamingResourceTypeName(surfaceNamer.getTypeNameDoc(context.getTypeTable(), methodConfig.getPageStreaming().getResourcesField().getType()));
    }
    docBuilder.throwsDocLines(surfaceNamer.getThrowsDocLines(methodConfig));
    return docBuilder.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) ApiMethodDocView(com.google.api.codegen.viewmodel.ApiMethodDocView)

Example 7 with MethodModel

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

the class DynamicLangApiMethodTransformer method generateMethod.

public OptionalArrayMethodView generateMethod(GapicMethodContext context, boolean packageHasMultipleServices) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    OptionalArrayMethodView.Builder apiMethod = OptionalArrayMethodView.newBuilder();
    if (context.getMethodConfig().isPageStreaming()) {
        apiMethod.type(ClientMethodType.PagedOptionalArrayMethod);
        apiMethod.pageStreamingView(pageStreamingTransformer.generateDescriptor(context.getSurfaceInterfaceContext(), method));
    } else {
        apiMethod.type(ClientMethodType.OptionalArrayMethod);
    }
    apiMethod.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    apiMethod.fullyQualifiedApiClassName(namer.getFullyQualifiedApiWrapperClassName(context.getInterfaceConfig()));
    apiMethod.topLevelAliasedApiClassName(namer.getTopLevelAliasedApiClassName((context.getInterfaceConfig()), packageHasMultipleServices));
    apiMethod.versionAliasedApiClassName(namer.getVersionAliasedApiClassName((context.getInterfaceConfig()), packageHasMultipleServices));
    apiMethod.apiVariableName(namer.getApiWrapperVariableName(context.getInterfaceConfig()));
    apiMethod.apiModuleName(namer.getApiWrapperModuleName());
    apiMethod.localPackageName(namer.getLocalPackageName());
    InitCodeOutputType initCodeOutputType = context.getMethodModel().getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
    InitCodeView initCode = initCodeTransformer.generateInitCode(context.cloneWithEmptyTypeTable(), createInitCodeContext(context, context.getMethodConfig().getRequiredFieldConfigs(), initCodeOutputType));
    apiMethod.initCode(initCode);
    apiMethod.doc(generateMethodDoc(context));
    apiMethod.name(namer.getApiMethodName(method, context.getMethodConfig().getVisibility()));
    apiMethod.requestVariableName(namer.getRequestVariableName(method));
    apiMethod.requestTypeName(namer.getAndSaveTypeName(context.getTypeTable(), context.getMethodModel().getInputType()));
    apiMethod.responseTypeName(namer.getAndSaveTypeName(context.getTypeTable(), context.getMethodModel().getOutputType()));
    apiMethod.hasReturnValue(!ServiceMessages.s_isEmptyType(context.getMethod().getOutputType()));
    apiMethod.key(namer.getMethodKey(method));
    apiMethod.grpcMethodName(namer.getGrpcMethodName(method));
    apiMethod.rerouteToGrpcInterface(context.getMethodConfig().getRerouteToGrpcInterface());
    apiMethod.stubName(namer.getStubName(context.getTargetInterface()));
    apiMethod.methodParams(apiMethodParamTransformer.generateMethodParams(context));
    Iterable<FieldConfig> filteredFieldConfigs = removePageTokenFieldConfig(context, context.getMethodConfig().getOptionalFieldConfigs());
    List<RequestObjectParamView> requiredParams = generateRequestObjectParams(context, context.getMethodConfig().getRequiredFieldConfigs());
    List<RequestObjectParamView> optionalParams = generateRequestObjectParams(context, context.getMethodConfig().getOptionalFieldConfigs());
    List<RequestObjectParamView> optionalParamsNoPageToken = generateRequestObjectParams(context, filteredFieldConfigs);
    apiMethod.requiredRequestObjectParams(requiredParams);
    apiMethod.optionalRequestObjectParams(optionalParams);
    apiMethod.optionalRequestObjectParamsNoPageToken(optionalParamsNoPageToken);
    apiMethod.hasRequestParameters(!requiredParams.isEmpty() || !optionalParamsNoPageToken.isEmpty());
    apiMethod.hasRequiredParameters(!requiredParams.isEmpty());
    GrpcStreamingType grpcStreamingType = context.getMethodConfig().getGrpcStreamingType();
    apiMethod.grpcStreamingType(grpcStreamingType);
    apiMethod.isSingularRequestMethod(grpcStreamingType.equals(GrpcStreamingType.NonStreaming) || grpcStreamingType.equals(GrpcStreamingType.ServerStreaming));
    apiMethod.packageName(namer.getPackageName());
    apiMethod.packageHasMultipleServices(packageHasMultipleServices);
    apiMethod.packageServiceName(namer.getPackageServiceName(context.getInterfaceConfig()));
    apiMethod.apiVersion(namer.getApiWrapperModuleVersion());
    apiMethod.longRunningView(context.getMethodConfig().isLongRunningOperation() ? lroTransformer.generateDetailView(context) : null);
    apiMethod.oneofParams(context.getMethodConfig().getOneofNames(namer));
    apiMethod.headerRequestParams(headerRequestParamTransformer.generateHeaderRequestParams(context));
    return apiMethod.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) FieldConfig(com.google.api.codegen.config.FieldConfig) GrpcStreamingType(com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Example 8 with MethodModel

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

the class GrpcStubTransformer method generateGrpcStub.

GrpcStubView generateGrpcStub(InterfaceContext context, InterfaceModel targetInterface, List<MethodModel> methods) {
    SurfaceNamer namer = context.getNamer();
    GrpcStubView.Builder stub = GrpcStubView.newBuilder();
    stub.name(namer.getStubName(targetInterface));
    stub.fullyQualifiedType(namer.getFullyQualifiedStubType(targetInterface));
    stub.createStubFunctionName(namer.getCreateStubFunctionName(targetInterface));
    String grpcClientTypeName = namer.getAndSaveNicknameForGrpcClientTypeName(context.getImportTypeTable(), targetInterface);
    stub.grpcClientTypeName(grpcClientTypeName);
    stub.grpcClientVariableName(namer.getGrpcClientVariableName(targetInterface));
    stub.grpcClientImportName(namer.getGrpcClientImportName(targetInterface));
    List<String> methodNames = new ArrayList<>();
    for (MethodModel method : methods) {
        methodNames.add(namer.getApiMethodName(method, context.getMethodConfig(method).getVisibility()));
    }
    stub.methodNames(methodNames);
    stub.stubMethodsArrayName(namer.getStubMethodsArrayName(targetInterface));
    stub.namespace(namer.getNamespace(targetInterface));
    stub.protoFileName(targetInterface.getFileSimpleName());
    return stub.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ArrayList(java.util.ArrayList) GrpcStubView(com.google.api.codegen.viewmodel.GrpcStubView)

Example 9 with MethodModel

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

the class GrpcStubTransformer method generateGrpcStubs.

public List<GrpcStubView> generateGrpcStubs(InterfaceContext context) {
    List<GrpcStubView> stubs = new ArrayList<>();
    Map<String, InterfaceModel> interfaces = new TreeMap<>();
    Map<String, List<MethodModel>> methods = new TreeMap<>();
    for (MethodModel method : context.getSupportedMethods()) {
        InterfaceModel targetInterface = context.asRequestMethodContext(method).getTargetInterface();
        interfaces.put(targetInterface.getFullName(), targetInterface);
        if (methods.containsKey(targetInterface.getFullName())) {
            methods.get(targetInterface.getFullName()).add(method);
        } else {
            methods.put(targetInterface.getFullName(), new ArrayList<>(Arrays.asList(method)));
        }
    }
    for (Map.Entry<String, InterfaceModel> entry : interfaces.entrySet()) {
        InterfaceModel apiInterface = entry.getValue();
        stubs.add(generateGrpcStub(context, apiInterface, methods.get(entry.getKey())));
    }
    return stubs;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ArrayList(java.util.ArrayList) GrpcStubView(com.google.api.codegen.viewmodel.GrpcStubView) TreeMap(java.util.TreeMap) InterfaceModel(com.google.api.codegen.config.InterfaceModel) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 10 with MethodModel

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

the class PageStreamingTransformer method generateDescriptorClass.

private PageStreamingDescriptorClassView generateDescriptorClass(MethodContext context) {
    SurfaceNamer namer = context.getNamer();
    ImportTypeTable typeTable = context.getTypeTable();
    MethodModel method = context.getMethodModel();
    PageStreamingConfig pageStreaming = context.getMethodConfig().getPageStreaming();
    PageStreamingDescriptorClassView.Builder desc = PageStreamingDescriptorClassView.newBuilder();
    FieldModel resourceField = pageStreaming.getResourcesField();
    FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
    desc.name(namer.getPageStreamingDescriptorConstName(method));
    desc.typeName(namer.getAndSavePagedResponseTypeName(context, resourceFieldConfig));
    desc.requestTypeName(method.getAndSaveRequestTypeName(typeTable, namer));
    desc.responseTypeName(method.getAndSaveResponseTypeName(typeTable, namer));
    desc.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceField));
    desc.tokenTypeName(typeTable.getAndSaveNicknameFor(pageStreaming.getResponseTokenField()));
    desc.defaultTokenValue(typeTable.getSnippetZeroValueAndSaveNicknameFor(pageStreaming.getResponseTokenField()));
    desc.requestTokenSetFunction(namer.getFieldSetFunctionName(pageStreaming.getRequestTokenField()));
    if (pageStreaming.hasPageSizeField()) {
        desc.requestPageSizeSetFunction(namer.getFieldSetFunctionName(pageStreaming.getPageSizeField()));
        desc.requestPageSizeGetFunction(namer.getFieldGetFunctionName(pageStreaming.getPageSizeField()));
    }
    desc.responseTokenGetFunction(namer.getFieldGetFunctionName(pageStreaming.getResponseTokenField()));
    ImmutableList.Builder<String> resourcesFieldGetFunctionList = new ImmutableList.Builder<>();
    for (FieldModel field : resourceFieldConfig.getFieldPath()) {
        resourcesFieldGetFunctionList.add(namer.getFieldGetFunctionName(field));
    }
    desc.resourcesFieldGetFunctions(resourcesFieldGetFunctionList.build());
    return desc.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) FieldConfig(com.google.api.codegen.config.FieldConfig) ImmutableList(com.google.common.collect.ImmutableList) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) FieldModel(com.google.api.codegen.config.FieldModel) PageStreamingDescriptorClassView(com.google.api.codegen.viewmodel.PageStreamingDescriptorClassView)

Aggregations

MethodModel (com.google.api.codegen.config.MethodModel)95 ArrayList (java.util.ArrayList)30 MethodConfig (com.google.api.codegen.config.MethodConfig)29 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)23 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)20 ImmutableList (com.google.common.collect.ImmutableList)16 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)14 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)14 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)12 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)11 FieldConfig (com.google.api.codegen.config.FieldConfig)11 ProtoMethodModel (com.google.api.codegen.config.ProtoMethodModel)9 Test (org.junit.Test)9 FieldModel (com.google.api.codegen.config.FieldModel)8 MethodContext (com.google.api.codegen.transformer.MethodContext)8 SymbolTable (com.google.api.codegen.util.SymbolTable)8 TypeModel (com.google.api.codegen.config.TypeModel)7 TestCaseView (com.google.api.codegen.viewmodel.testing.TestCaseView)7 InterfaceModel (com.google.api.codegen.config.InterfaceModel)6 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)6