use of com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType 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();
}
use of com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType in project toolkit by googleapis.
the class DynamicLangApiMethodTransformer method generateMethodCommon.
private void generateMethodCommon(GapicMethodContext context, InitCodeContext initContext, boolean packageHasMultipleServices, MethodModel method, OptionalArrayMethodView.Builder apiMethod, List<CallingForm> callingForms, SampleContext sampleContext) {
SurfaceNamer namer = context.getNamer();
apiMethod.apiClassName(namer.getApiWrapperClassName(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());
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());
GrpcStreamingType grpcStreamingType = context.getMethodConfig().getGrpcStreamingType();
apiMethod.grpcStreamingType(grpcStreamingType);
apiMethod.isSingularRequestMethod(grpcStreamingType.equals(GrpcStreamingType.NonStreaming) || grpcStreamingType.equals(GrpcStreamingType.ServerStreaming));
apiMethod.packageName(namer.getPackageName());
apiMethod.apiVersion(namer.getApiWrapperModuleVersion());
apiMethod.oneofParams(context.getMethodConfig().getOneofNames(namer));
apiMethod.headerRequestParams(headerRequestParamTransformer.generateHeaderRequestParams(context));
InitCodeOutputType initCodeOutputType = context.getMethodModel().getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
if (sampleContext == null) {
sampleTransformer.generateSamples(apiMethod, context, initContext, context.getMethodConfig().getRequiredFieldConfigs(), initCodeOutputType, callingForms);
} else {
MethodSampleView sampleView = sampleTransformer.generateSample(context, sampleContext);
apiMethod.samples(ImmutableList.of(sampleView));
}
}
Aggregations