Search in sources :

Example 1 with FieldConfig

use of com.google.api.codegen.config.FieldConfig 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 2 with FieldConfig

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

the class StaticLangApiMethodTransformer method setFlattenedMethodFields.

private void setFlattenedMethodFields(MethodContext context, List<ParamWithSimpleDoc> additionalParams, Synchronicity synchronicity, StaticLangApiMethodView.Builder methodViewBuilder) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    Iterable<FieldConfig> fieldConfigs = context.getFlatteningConfig().getFlattenedFieldConfigs().values();
    methodViewBuilder.initCode(initCodeTransformer.generateInitCode(context.cloneWithEmptyTypeTable(), createInitCodeContext(context, fieldConfigs, InitCodeOutputType.FieldList)));
    methodViewBuilder.doc(ApiMethodDocView.newBuilder().mainDocLines(namer.getDocLines(method, context.getMethodConfig())).paramDocs(getMethodParamDocs(context, fieldConfigs, additionalParams)).throwsDocLines(namer.getThrowsDocLines(context.getMethodConfig())).returnsDocLines(namer.getReturnDocLines(context.getSurfaceInterfaceContext(), context, synchronicity)).build());
    List<RequestObjectParamView> params = new ArrayList<>();
    for (FieldConfig fieldConfig : fieldConfigs) {
        params.add(resourceObjectTransformer.generateRequestObjectParam(context, fieldConfig));
    }
    methodViewBuilder.forwardingMethodParams(params);
    List<RequestObjectParamView> nonforwardingParams = new ArrayList<>(params);
    nonforwardingParams.addAll(ParamWithSimpleDoc.asRequestObjectParamViews(additionalParams));
    methodViewBuilder.methodParams(nonforwardingParams);
    methodViewBuilder.requestObjectParams(params);
    methodViewBuilder.pathTemplateChecks(generatePathTemplateChecks(context, fieldConfigs));
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView)

Example 3 with FieldConfig

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

the class CSharpGapicSnippetsTransformer method generatePagedFlattenedAsyncMethod.

private StaticLangApiMethodSnippetView generatePagedFlattenedAsyncMethod(MethodContext methodContext, String suffix, boolean requiresNamedArguments) {
    StaticLangApiMethodView method = generateInitCode(apiMethodTransformer.generatePagedFlattenedAsyncMethod(methodContext, csharpCommonTransformer.pagedMethodAdditionalParams(), null), methodContext, methodContext.getFlatteningConfig().getFlattenedFieldConfigs().values(), InitCodeOutputType.FieldList, CallingForm.FlattenedAsyncPaged);
    SurfaceNamer namer = methodContext.getNamer();
    PageStreamingConfig pageStreaming = methodContext.getMethodConfig().getPageStreaming();
    FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
    String callerResponseTypeName = namer.getAndSaveCallerAsyncPagedResponseTypeName(methodContext, resourceFieldConfig);
    return StaticLangApiMethodSnippetView.newBuilder().method(method).snippetMethodName(method.name() + suffix).callerResponseTypeName(callerResponseTypeName).apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())).apiVariableName(method.apiVariableName()).requiresNamedArguments(requiresNamedArguments).build();
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) FieldConfig(com.google.api.codegen.config.FieldConfig) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 4 with FieldConfig

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

the class CSharpGapicSnippetsTransformer method generatePagedFlattenedMethod.

private StaticLangApiMethodSnippetView generatePagedFlattenedMethod(MethodContext methodContext, String suffix, boolean requiresNamedArguments) {
    StaticLangApiMethodView method = generateInitCode(apiMethodTransformer.generatePagedFlattenedMethod(methodContext, csharpCommonTransformer.pagedMethodAdditionalParams(), null), methodContext, methodContext.getFlatteningConfig().getFlattenedFieldConfigs().values(), InitCodeOutputType.FieldList, CallingForm.FlattenedPaged);
    SurfaceNamer namer = methodContext.getNamer();
    PageStreamingConfig pageStreaming = methodContext.getMethodConfig().getPageStreaming();
    FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
    String callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, resourceFieldConfig);
    return StaticLangApiMethodSnippetView.newBuilder().method(method).snippetMethodName(method.name() + suffix).callerResponseTypeName(callerResponseTypeName).apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())).apiVariableName(method.apiVariableName()).requiresNamedArguments(requiresNamedArguments).build();
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) FieldConfig(com.google.api.codegen.config.FieldConfig) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 5 with FieldConfig

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

the class CSharpGapicSmokeTestTransformer method createSmokeTestCaseApiMethodView.

private StaticLangApiMethodView createSmokeTestCaseApiMethodView(GapicInterfaceContext context, MethodContext methodContext) {
    SurfaceNamer namer = context.getNamer();
    MethodConfig methodConfig = methodContext.getMethodConfig();
    StaticLangApiMethodView.Builder apiMethodView;
    if (methodConfig.isPageStreaming()) {
        apiMethodView = apiMethodTransformer.generatePagedFlattenedMethod(methodContext, null).toBuilder();
        FieldConfig resourceFieldConfig = methodContext.getMethodConfig().getPageStreaming().getResourcesFieldConfig();
        String callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, resourceFieldConfig);
        apiMethodView.responseTypeName(callerResponseTypeName);
    } else if (methodContext.isLongRunningMethodContext()) {
        ArrayList<ParamWithSimpleDoc> emptyParams = new ArrayList<ParamWithSimpleDoc>();
        apiMethodView = apiMethodTransformer.generateOperationFlattenedMethod(methodContext, emptyParams, null).toBuilder();
    } else {
        apiMethodView = apiMethodTransformer.generateFlattenedMethod(methodContext, null).toBuilder();
    }
    InitCodeTransformer initCodeTransformer = new InitCodeTransformer();
    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) ParamWithSimpleDoc(com.google.api.codegen.transformer.ParamWithSimpleDoc) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) InitCodeTransformer(com.google.api.codegen.transformer.InitCodeTransformer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Aggregations

FieldConfig (com.google.api.codegen.config.FieldConfig)40 MethodModel (com.google.api.codegen.config.MethodModel)16 ArrayList (java.util.ArrayList)15 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)14 FieldModel (com.google.api.codegen.config.FieldModel)11 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)11 MethodConfig (com.google.api.codegen.config.MethodConfig)7 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)7 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)6 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)5 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)5 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)5 InitCodeContext (com.google.api.codegen.metacode.InitCodeContext)4 SymbolTable (com.google.api.codegen.util.SymbolTable)4 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)4 MethodContext (com.google.api.codegen.config.MethodContext)3 InitCodeNode (com.google.api.codegen.metacode.InitCodeNode)3 GrpcStreamingType (com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType)2 ResourceNameConfig (com.google.api.codegen.config.ResourceNameConfig)2 ResourceNameMessageConfigs (com.google.api.codegen.config.ResourceNameMessageConfigs)2