use of com.google.api.codegen.viewmodel.RequestObjectParamView in project toolkit by googleapis.
the class StaticLangApiMethodTransformer method setCallableMethodFields.
private void setCallableMethodFields(MethodContext context, String callableName, Builder methodViewBuilder, List<CallingForm> callingForms, SampleContext sampleContext) {
MethodModel method = context.getMethodModel();
methodViewBuilder.doc(ApiMethodDocView.newBuilder().mainDocLines(context.getNamer().getDocLines(method, context.getMethodConfig())).paramDocs(new ArrayList<ParamDocView>()).throwsDocLines(new ArrayList<String>()).build());
if (sampleContext == null) {
sampleTransformer.generateSamples(methodViewBuilder, context, context.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, callingForms);
} else {
MethodSampleView sampleView = sampleTransformer.generateSample(context, sampleContext);
methodViewBuilder.samples(ImmutableList.of(sampleView));
}
methodViewBuilder.methodParams(new ArrayList<RequestObjectParamView>());
methodViewBuilder.requestObjectParams(new ArrayList<RequestObjectParamView>());
methodViewBuilder.pathTemplateChecks(new ArrayList<PathTemplateCheckView>());
String requestTypeFullName = context.getMethodModel().getInputTypeName(context.getTypeTable()).getFullName();
String requestType = context.getTypeTable().getAndSaveNicknameFor(requestTypeFullName);
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().requestType(requestType).genericAwareResponseType(genericAwareResponseType).callableName(callableName).interfaceTypeName(context.getNamer().getApiCallableTypeName(callableImplType.serviceMethodType())).build());
}
use of com.google.api.codegen.viewmodel.RequestObjectParamView 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));
}
}
use of com.google.api.codegen.viewmodel.RequestObjectParamView in project toolkit by googleapis.
the class StaticLangResourceObjectTransformer method generateRequestObjectParam.
public RequestObjectParamView generateRequestObjectParam(MethodContext context, FieldConfig fieldConfig) {
SurfaceNamer namer = context.getNamer();
FeatureConfig featureConfig = context.getFeatureConfig();
ImportTypeTable typeTable = context.getTypeTable();
FieldModel field = fieldConfig.getField();
Iterable<FieldModel> requiredFields = context.getMethodConfig().getRequiredFields();
boolean isRequired = false;
for (FieldModel f : requiredFields) {
if (f.getSimpleName().equals(field.getSimpleName())) {
isRequired = true;
break;
}
}
String typeName = namer.getNotImplementedString("StaticLangApiMethodTransformer.generateRequestObjectParam - typeName");
String elementTypeName = namer.getNotImplementedString("StaticLangApiMethodTransformer.generateRequestObjectParam - elementTypeName");
if (context.getFeatureConfig().useResourceNameFormatOption(fieldConfig)) {
if (namer.shouldImportRequestObjectParamType(field)) {
typeName = namer.getAndSaveResourceTypeName(typeTable, fieldConfig);
}
if (namer.shouldImportRequestObjectParamElementType(field)) {
// Use makeOptional to remove repeated property from type
elementTypeName = namer.getAndSaveElementResourceTypeName(typeTable, fieldConfig);
}
} else {
if (namer.shouldImportRequestObjectParamType(field)) {
typeName = typeTable.getAndSaveNicknameFor(field);
if (!isRequired) {
typeName = namer.makePrimitiveTypeNullable(typeName, field);
}
}
if (namer.shouldImportRequestObjectParamElementType(field)) {
elementTypeName = typeTable.getAndSaveNicknameForElementType(field);
}
}
String setCallName = namer.getFieldSetFunctionName(featureConfig, fieldConfig);
String getCallName = namer.getFieldGetFunctionName(field);
String transformParamFunctionName = null;
String formatMethodName = null;
if (context.getFeatureConfig().useResourceNameFormatOption(fieldConfig)) {
if (fieldConfig.requiresParamTransformation() && !fieldConfig.requiresParamTransformationFromAny() && !featureConfig.useInheritanceForOneofs()) {
transformParamFunctionName = namer.getResourceOneofCreateMethod(typeTable, fieldConfig);
}
if (context.getFeatureConfig().useResourceNameConverters(fieldConfig)) {
if (field.isRepeated()) {
// TODO support repeated one-ofs (in Java: Any* classes)
transformParamFunctionName = namer.getResourceTypeFormatListMethodName(context.getTypeTable(), fieldConfig);
} else {
formatMethodName = namer.getResourceNameFormatMethodName();
}
}
}
RequestObjectParamView.Builder param = RequestObjectParamView.newBuilder();
param.name(namer.getVariableName(field));
param.keyName(namer.getFieldKey(field));
param.nameAsMethodName(namer.getFieldGetFunctionName(featureConfig, fieldConfig));
param.typeName(typeName);
param.elementTypeName(elementTypeName);
param.setCallName(setCallName);
param.getCallName(getCallName);
param.transformParamFunctionName(transformParamFunctionName);
param.formatMethodName(formatMethodName);
param.isMap(field.isMap());
param.isArray(!field.isMap() && field.isRepeated());
param.isPrimitive(namer.isPrimitive(field));
param.isOptional(!isRequired);
if (!isRequired) {
param.optionalDefault(namer.getOptionalFieldDefaultValue(fieldConfig, context));
}
return param.build();
}
use of com.google.api.codegen.viewmodel.RequestObjectParamView in project toolkit by googleapis.
the class StaticLangApiMethodTransformer method setFlattenedMethodFields.
private void setFlattenedMethodFields(MethodContext context, List<ParamWithSimpleDoc> additionalParams, Synchronicity synchronicity, StaticLangApiMethodView.Builder methodViewBuilder, List<CallingForm> callingForms, SampleContext sampleContext) {
MethodModel method = context.getMethodModel();
SurfaceNamer namer = context.getNamer();
Collection<FieldConfig> fieldConfigs = context.getFlatteningConfig().getFlattenedFieldConfigs().values();
if (sampleContext == null) {
sampleTransformer.generateSamples(methodViewBuilder, context, fieldConfigs, InitCodeOutputType.FieldList, callingForms);
} else {
MethodSampleView sampleView = sampleTransformer.generateSample(context, sampleContext);
methodViewBuilder.samples(ImmutableList.of(sampleView));
}
methodViewBuilder.doc(ApiMethodDocView.newBuilder().mainDocLines(namer.getDocLines(method, context.getMethodConfig())).paramDocs(getMethodParamDocs(context, fieldConfigs, additionalParams)).throwsDocLines(namer.getThrowsDocLines(context.getMethodConfig())).returnsDocLines(namer.getReturnDocLines(context.getSurfaceInterfaceContext(), context, synchronicity)).build());
List<RequestObjectParamView> params = new ArrayList<>();
for (FieldConfig fieldConfig : fieldConfigs) {
params.add(resourceObjectTransformer.generateRequestObjectParam(context, fieldConfig));
}
methodViewBuilder.forwardingMethodParams(params);
List<RequestObjectParamView> nonforwardingParams = new ArrayList<>(params);
nonforwardingParams.addAll(ParamWithSimpleDoc.asRequestObjectParamViews(additionalParams));
methodViewBuilder.methodParams(nonforwardingParams);
methodViewBuilder.requestObjectParams(params);
methodViewBuilder.pathTemplateChecks(generatePathTemplateChecks(context, fieldConfigs));
}
use of com.google.api.codegen.viewmodel.RequestObjectParamView in project toolkit by googleapis.
the class JavaDiscoGapicRequestToViewTransformer method transform.
@Override
public List<ViewModel> transform(DiscoApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceRequests = new ArrayList<>();
String packageName = productConfig.getPackageName();
SurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
DiscoGapicInterfaceContext context = JavaDiscoGapicSurfaceTransformer.newInterfaceContext(apiInterface, productConfig, surfaceNamer, createTypeTable(productConfig.getPackageName()));
for (DiscoveryMethodModel method : context.getSupportedMethods()) {
RequestObjectParamView params = getRequestObjectParams(context, method);
SchemaTransformationContext requestContext = SchemaTransformationContext.create(method.getFullName(), context.getSchemaTypeTable(), context);
StaticLangApiMessageView requestView = generateRequestClass(requestContext, method, params);
surfaceRequests.add(generateRequestFile(requestContext, requestView));
}
}
surfaceRequests.sort((ViewModel o1, ViewModel o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath()));
return surfaceRequests;
}
Aggregations