use of com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType 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.metacode.InitCodeContext.InitCodeOutputType in project toolkit by googleapis.
the class PythonGapicSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
ImmutableList.Builder<TestCaseView> testCaseViews = ImmutableList.builder();
// certain string until all of the types have been disambiguated.
for (int i = 0; i < 2; ++i) {
testCaseViews = ImmutableList.builder();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
GapicMethodContext methodContext = context.asRequestMethodContext(method);
ClientMethodType clientMethodType = ClientMethodType.OptionalArrayMethod;
if (methodContext.getMethodConfig().isLongRunningOperation()) {
clientMethodType = ClientMethodType.OperationOptionalArrayMethod;
} else if (methodContext.getMethodConfig().isPageStreaming()) {
clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
}
Iterable<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
InitCodeOutputType initCodeOutputType = method.getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
InitCodeContext initCodeContext = InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(initCodeOutputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
}
}
return testCaseViews.build();
}
use of com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType in project toolkit by googleapis.
the class RubyGapicSurfaceTestTransformer method createUnitTestCaseInitCodeContext.
private InitCodeContext createUnitTestCaseInitCodeContext(GapicInterfaceContext context, MethodModel method) {
MethodContext requestMethodContext = context.asRequestMethodContext(method);
MethodContext dynamicMethodContext = context.asDynamicMethodContext(method);
MethodConfig methodConfig = requestMethodContext.getMethodConfig();
Iterable<FieldConfig> fieldConfigs = methodConfig.getRequiredFieldConfigs();
InitCodeOutputType outputType = method.getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
return InitCodeContext.newBuilder().initObjectType(method.getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodConfig.getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(dynamicMethodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(outputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).build();
}
use of com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType in project toolkit by googleapis.
the class PhpGapicSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
GapicMethodContext methodContext = context.asRequestMethodContext(method);
if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
// Issue: https://github.com/googleapis/toolkit/issues/946
continue;
}
InitCodeOutputType initCodeOutputType = InitCodeOutputType.FieldList;
if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.BidiStreaming) {
initCodeOutputType = InitCodeOutputType.SingleObject;
}
ClientMethodType clientMethodType = ClientMethodType.OptionalArrayMethod;
if (methodContext.getMethodConfig().isLongRunningOperation()) {
clientMethodType = ClientMethodType.OperationOptionalArrayMethod;
} else if (methodContext.getMethodConfig().isPageStreaming()) {
clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
}
Iterable<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
InitCodeContext initCodeContext = InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(initCodeOutputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
}
return testCaseViews;
}
Aggregations