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();
}
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();
}
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();
}
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;
}
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();
}
Aggregations