use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class StaticLangApiMethodTransformer method generateRequestObjectMethod.
public StaticLangApiMethodView generateRequestObjectMethod(MethodContext context, List<ParamWithSimpleDoc> additionalParams) {
MethodModel method = context.getMethodModel();
SurfaceNamer namer = context.getNamer();
StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
setCommonFields(context, methodViewBuilder);
methodViewBuilder.name(namer.getApiMethodName(method, context.getMethodConfig().getVisibility()));
methodViewBuilder.exampleName(namer.getApiMethodExampleName(context.getInterfaceConfig(), method));
setRequestObjectMethodFields(context, namer.getCallableMethodName(method), Synchronicity.Sync, additionalParams, methodViewBuilder);
setStaticLangReturnTypeName(context, methodViewBuilder);
return methodViewBuilder.type(ClientMethodType.RequestObjectMethod).build();
}
use of com.google.api.codegen.config.MethodModel 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());
}
use of com.google.api.codegen.config.MethodModel 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.config.MethodModel in project toolkit by googleapis.
the class CSharpCommonTransformer method getSupportedMethods.
public List<MethodModel> getSupportedMethods(InterfaceContext context) {
List<MethodModel> result = new ArrayList<>();
boolean mixinsDisabled = !context.getFeatureConfig().enableMixins();
for (MethodModel method : context.getSupportedMethods()) {
if (mixinsDisabled && context.getMethodConfig(method).getRerouteToGrpcInterface() != null) {
continue;
}
MethodConfig methodConfig = context.getMethodConfig(method);
if (methodConfig.getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
continue;
}
result.add(method);
}
return result;
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class CSharpCommonTransformer method generateReroutedGrpcView.
public List<ReroutedGrpcView> generateReroutedGrpcView(GapicInterfaceContext context) {
SurfaceNamer namer = context.getNamer();
Set<ReroutedGrpcView> reroutedViews = new LinkedHashSet<>();
for (MethodModel method : getSupportedMethods(context)) {
MethodConfig methodConfig = context.getMethodConfig(method);
String reroute = methodConfig.getRerouteToGrpcInterface();
if (reroute != null) {
ReroutedGrpcView rerouted = ReroutedGrpcView.newBuilder().grpcClientVarName(namer.getReroutedGrpcClientVarName(methodConfig)).typeName(namer.getReroutedGrpcTypeName(context.getImportTypeTable(), methodConfig)).getMethodName(namer.getReroutedGrpcMethodName(methodConfig)).build();
reroutedViews.add(rerouted);
}
}
return new ArrayList<ReroutedGrpcView>(reroutedViews);
}
Aggregations