Search in sources :

Example 1 with RequestObjectParamView

use of com.google.api.codegen.viewmodel.RequestObjectParamView 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 RequestObjectParamView

use of com.google.api.codegen.viewmodel.RequestObjectParamView in project toolkit by googleapis.

the class StaticLangApiMethodTransformer method setRequestObjectMethodFields.

private void setRequestObjectMethodFields(MethodContext context, String callableMethodName, Synchronicity sync, List<ParamWithSimpleDoc> additionalParams, StaticLangApiMethodView.Builder methodViewBuilder) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    List<ParamDocView> paramDocs = new ArrayList<>();
    paramDocs.addAll(getRequestObjectParamDocs(context));
    paramDocs.addAll(ParamWithSimpleDoc.asParamDocViews(additionalParams));
    methodViewBuilder.doc(ApiMethodDocView.newBuilder().mainDocLines(namer.getDocLines(method, context.getMethodConfig())).paramDocs(paramDocs).throwsDocLines(namer.getThrowsDocLines(context.getMethodConfig())).returnsDocLines(namer.getReturnDocLines(context.getSurfaceInterfaceContext(), context, sync)).build());
    InitCodeView initCode = initCodeTransformer.generateInitCode(context.cloneWithEmptyTypeTable(), createInitCodeContext(context, context.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject));
    methodViewBuilder.initCode(initCode);
    methodViewBuilder.methodParams(new ArrayList<RequestObjectParamView>());
    methodViewBuilder.requestObjectParams(new ArrayList<RequestObjectParamView>());
    methodViewBuilder.pathTemplateChecks(new ArrayList<PathTemplateCheckView>());
    RequestObjectMethodDetailView.Builder detailBuilder = RequestObjectMethodDetailView.newBuilder();
    if (context.getMethodConfig().hasRequestObjectMethod()) {
        detailBuilder.accessModifier(context.getNamer().getVisiblityKeyword(context.getMethodConfig().getVisibility()));
    } else {
        detailBuilder.accessModifier(context.getNamer().getPrivateAccessModifier());
    }
    detailBuilder.callableMethodName(callableMethodName);
    methodViewBuilder.requestObjectMethod(detailBuilder.build());
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) PathTemplateCheckView(com.google.api.codegen.viewmodel.PathTemplateCheckView) ArrayList(java.util.ArrayList) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView) RequestObjectMethodDetailView(com.google.api.codegen.viewmodel.RequestObjectMethodDetailView) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Example 3 with RequestObjectParamView

use of com.google.api.codegen.viewmodel.RequestObjectParamView 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 4 with RequestObjectParamView

use of com.google.api.codegen.viewmodel.RequestObjectParamView 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 5 with RequestObjectParamView

use of com.google.api.codegen.viewmodel.RequestObjectParamView in project toolkit by googleapis.

the class StaticLangApiMethodTransformer method setRequestObjectMethodFields.

private void setRequestObjectMethodFields(MethodContext context, String callableMethodName, Synchronicity sync, List<ParamWithSimpleDoc> additionalParams, StaticLangApiMethodView.Builder methodViewBuilder, List<CallingForm> callingForms, SampleContext sampleContext) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    List<ParamDocView> paramDocs = new ArrayList<>();
    paramDocs.addAll(getRequestObjectParamDocs(context));
    paramDocs.addAll(ParamWithSimpleDoc.asParamDocViews(additionalParams));
    methodViewBuilder.doc(ApiMethodDocView.newBuilder().mainDocLines(namer.getDocLines(method, context.getMethodConfig())).paramDocs(paramDocs).throwsDocLines(namer.getThrowsDocLines(context.getMethodConfig())).returnsDocLines(namer.getReturnDocLines(context.getSurfaceInterfaceContext(), context, sync)).build());
    if (sampleContext == null) {
        sampleTransformer.generateSamples(methodViewBuilder, context, context.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, callingForms);
    } else {
        MethodSampleView sampleView = sampleTransformer.generateSample(context, sampleContext);
        methodViewBuilder.samples(ImmutableList.of(sampleView));
    }
    methodViewBuilder.methodParams(new ArrayList<RequestObjectParamView>());
    methodViewBuilder.requestObjectParams(new ArrayList<RequestObjectParamView>());
    methodViewBuilder.pathTemplateChecks(new ArrayList<PathTemplateCheckView>());
    RequestObjectMethodDetailView.Builder detailBuilder = RequestObjectMethodDetailView.newBuilder();
    detailBuilder.accessModifier(context.getNamer().getVisiblityKeyword(context.getMethodConfig().getVisibility()));
    detailBuilder.callableMethodName(callableMethodName);
    methodViewBuilder.requestObjectMethod(detailBuilder.build());
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) MethodSampleView(com.google.api.codegen.viewmodel.MethodSampleView) PathTemplateCheckView(com.google.api.codegen.viewmodel.PathTemplateCheckView) ArrayList(java.util.ArrayList) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView) RequestObjectMethodDetailView(com.google.api.codegen.viewmodel.RequestObjectMethodDetailView)

Aggregations

RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)11 MethodModel (com.google.api.codegen.config.MethodModel)7 ArrayList (java.util.ArrayList)7 FieldConfig (com.google.api.codegen.config.FieldConfig)4 MethodSampleView (com.google.api.codegen.viewmodel.MethodSampleView)4 PathTemplateCheckView (com.google.api.codegen.viewmodel.PathTemplateCheckView)4 FieldModel (com.google.api.codegen.config.FieldModel)2 GrpcStreamingType (com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType)2 MethodConfig (com.google.api.codegen.config.MethodConfig)2 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)2 ApiCallableImplType (com.google.api.codegen.viewmodel.ApiCallableImplType)2 InitCodeView (com.google.api.codegen.viewmodel.InitCodeView)2 ParamDocView (com.google.api.codegen.viewmodel.ParamDocView)2 RequestObjectMethodDetailView (com.google.api.codegen.viewmodel.RequestObjectMethodDetailView)2 SimpleParamDocView (com.google.api.codegen.viewmodel.SimpleParamDocView)2 DiscoGapicInterfaceContext (com.google.api.codegen.config.DiscoGapicInterfaceContext)1 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)1 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 SchemaTransformationContext (com.google.api.codegen.discogapic.SchemaTransformationContext)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1