use of com.google.api.codegen.viewmodel.RequestObjectParamView in project toolkit by googleapis.
the class DynamicLangApiMethodTransformer method generateRequestObjectParam.
private RequestObjectParamView generateRequestObjectParam(GapicMethodContext context, FieldConfig fieldConfig) {
SurfaceNamer namer = context.getNamer();
FeatureConfig featureConfig = context.getFeatureConfig();
ModelTypeTable 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;
}
}
RequestObjectParamView.Builder param = RequestObjectParamView.newBuilder();
param.name(namer.getVariableName(field));
param.keyName(namer.getFieldKey(field));
param.nameAsMethodName(namer.getFieldGetFunctionName(featureConfig, fieldConfig));
param.typeName(typeTable.getAndSaveNicknameFor(field));
param.elementTypeName(typeTable.getAndSaveNicknameForElementType(field));
param.setCallName(namer.getFieldSetFunctionName(featureConfig, fieldConfig));
param.getCallName(namer.getFieldGetFunctionName(featureConfig, fieldConfig));
param.isMap(field.isMap());
param.isArray(!field.isMap() && field.isRepeated());
param.isPrimitive(field.isPrimitive());
param.isOptional(!isRequired);
if (!isRequired) {
param.optionalDefault(namer.getOptionalFieldDefaultValue(fieldConfig, context));
}
return param.build();
}
Aggregations