use of com.google.api.codegen.viewmodel.InitCodeView 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.viewmodel.InitCodeView 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());
}
use of com.google.api.codegen.viewmodel.InitCodeView in project toolkit by googleapis.
the class TestCaseTransformer method createTestCaseView.
public TestCaseView createTestCaseView(MethodContext methodContext, SymbolTable testNameTable, InitCodeContext initCodeContext, ClientMethodType clientMethodType, Synchronicity synchronicity, InitCodeContext requestObjectInitCodeContext) {
MethodModel method = methodContext.getMethodModel();
MethodConfig methodConfig = methodContext.getMethodConfig();
SurfaceNamer namer = methodContext.getNamer();
ImportTypeTable typeTable = methodContext.getTypeTable();
String clientMethodName;
String responseTypeName;
String callerResponseTypeName;
String fullyQualifiedResponseTypeName = methodContext.getMethodModel().getOutputTypeName(typeTable).getFullName();
if (methodConfig.isPageStreaming()) {
clientMethodName = namer.getApiMethodName(method, methodConfig.getVisibility());
responseTypeName = namer.getAndSavePagedResponseTypeName(methodContext, methodConfig.getPageStreaming().getResourcesFieldConfig());
callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, methodConfig.getPageStreaming().getResourcesFieldConfig());
} else if (methodConfig.isLongRunningOperation()) {
clientMethodName = namer.getLroApiMethodName(method, methodConfig.getVisibility());
responseTypeName = methodContext.getTypeTable().getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getReturnType());
callerResponseTypeName = responseTypeName;
fullyQualifiedResponseTypeName = methodContext.getTypeTable().getFullNameFor(methodConfig.getLongRunningConfig().getReturnType());
} else if (clientMethodType == ClientMethodType.CallableMethod) {
clientMethodName = namer.getCallableMethodName(method);
responseTypeName = method.getAndSaveResponseTypeName(typeTable, namer);
callerResponseTypeName = responseTypeName;
} else {
clientMethodName = synchronicity == Synchronicity.Sync ? namer.getApiMethodName(method, methodConfig.getVisibility()) : namer.getAsyncApiMethodName(method, methodConfig.getVisibility());
responseTypeName = method.getAndSaveResponseTypeName(typeTable, namer);
callerResponseTypeName = responseTypeName;
}
InitCodeView initCode = initCodeTransformer.generateInitCode(methodContext, initCodeContext);
InitCodeView requestObjectInitCode = requestObjectInitCodeContext != null ? initCodeTransformer.generateInitCode(methodContext, requestObjectInitCodeContext) : null;
boolean hasRequestParameters = initCode.lines().size() > 0;
boolean hasReturnValue = !method.isOutputTypeEmpty();
if (methodConfig.isLongRunningOperation()) {
hasReturnValue = !methodConfig.getLongRunningConfig().getReturnType().isEmptyType();
}
InitCodeContext responseInitCodeContext = createResponseInitCodeContext(methodContext, initCodeContext.symbolTable());
MockRpcResponseView mockRpcResponseView = createMockResponseView(methodContext, responseInitCodeContext);
GrpcStreamingView grpcStreamingView = null;
if (methodConfig.isGrpcStreaming()) {
String resourceTypeName = null;
String resourcesFieldGetterName = null;
if (methodConfig.getGrpcStreaming().hasResourceField()) {
FieldModel resourcesField = methodConfig.getGrpcStreaming().getResourcesField();
resourceTypeName = methodContext.getTypeTable().getAndSaveNicknameForElementType(resourcesField);
resourcesFieldGetterName = namer.getFieldGetFunctionName(resourcesField, Name.from(resourcesField.getSimpleName()));
}
grpcStreamingView = GrpcStreamingView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterName(resourcesFieldGetterName).requestInitCodeList(createGrpcStreamingInitCodeViews(methodContext, initCodeContext, initCode)).responseInitCodeList(createGrpcStreamingInitCodeViews(methodContext, responseInitCodeContext, mockRpcResponseView.initCode())).build();
}
return TestCaseView.newBuilder().asserts(initCodeTransformer.generateRequestAssertViews(methodContext, initCodeContext)).clientMethodType(clientMethodType).grpcStreamingType(methodConfig.getGrpcStreamingType()).hasRequestParameters(hasRequestParameters).hasReturnValue(hasReturnValue).initCode(initCode).requestObjectInitCode(requestObjectInitCode).mockResponse(mockRpcResponseView).mockServiceVarName(namer.getMockServiceVarName(methodContext.getTargetInterface())).name(synchronicity == Synchronicity.Sync ? namer.getTestCaseName(testNameTable, method) : namer.getAsyncTestCaseName(testNameTable, method)).nameWithException(namer.getExceptionTestCaseName(testNameTable, method)).pageStreamingResponseViews(createPageStreamingResponseViews(methodContext)).grpcStreamingView(grpcStreamingView).requestTypeName(method.getAndSaveRequestTypeName(typeTable, namer)).responseTypeName(responseTypeName).callerResponseTypeName(callerResponseTypeName).fullyQualifiedRequestTypeName(method.getInputTypeName(typeTable).getFullName()).fullyQualifiedResponseTypeName(fullyQualifiedResponseTypeName).serviceConstructorName(namer.getApiWrapperClassConstructorName(methodContext.getInterfaceConfig())).fullyQualifiedServiceClassName(namer.getFullyQualifiedApiWrapperClassName(methodContext.getInterfaceConfig())).fullyQualifiedAliasedServiceClassName(namer.getTopLevelAliasedApiClassName((methodContext.getInterfaceConfig()), packageHasMultipleServices)).clientMethodName(clientMethodName).mockGrpcStubTypeName(namer.getMockGrpcServiceImplName(methodContext.getTargetInterface())).createStubFunctionName(namer.getCreateStubFunctionName(methodContext.getTargetInterface())).grpcStubCallString(namer.getGrpcStubCallString(methodContext.getTargetInterface(), method)).clientHasDefaultInstance(methodContext.getInterfaceConfig().hasDefaultInstance()).methodDescriptor(getMethodDescriptorName(methodContext)).grpcMethodName(synchronicity == Synchronicity.Sync ? namer.getGrpcMethodName(method) : namer.getAsyncGrpcMethodName(method)).build();
}
use of com.google.api.codegen.viewmodel.InitCodeView in project toolkit by googleapis.
the class TestCaseTransformer method createMockResponseView.
private MockRpcResponseView createMockResponseView(MethodContext methodContext, InitCodeContext responseInitCodeContext) {
methodContext = methodContext.getSurfaceInterfaceContext().asRequestMethodContext(methodContext.getMethodModel());
InitCodeView initCodeView = initCodeTransformer.generateInitCode(methodContext, responseInitCodeContext);
String typeName = methodContext.getMethodModel().getAndSaveResponseTypeName(methodContext.getTypeTable(), methodContext.getNamer());
return MockRpcResponseView.newBuilder().typeName(typeName).initCode(initCodeView).build();
}
use of com.google.api.codegen.viewmodel.InitCodeView 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).toBuilder();
FieldConfig resourceFieldConfig = methodContext.getMethodConfig().getPageStreaming().getResourcesFieldConfig();
String callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, resourceFieldConfig);
apiMethodView.responseTypeName(callerResponseTypeName);
} else if (methodConfig.isLongRunningOperation()) {
ArrayList<ParamWithSimpleDoc> emptyParams = new ArrayList<ParamWithSimpleDoc>();
apiMethodView = apiMethodTransformer.generateOperationFlattenedMethod(methodContext, emptyParams).toBuilder();
} else {
apiMethodView = apiMethodTransformer.generateFlattenedMethod(methodContext).toBuilder();
}
InitCodeTransformer initCodeTransformer = new InitCodeTransformer();
InitCodeView initCodeView = initCodeTransformer.generateInitCode(methodContext, testCaseTransformer.createSmokeTestInitContext(methodContext));
apiMethodView.initCode(initCodeView);
return apiMethodView.build();
}
Aggregations