Allow better default value in parameters using codegen property (#15882)

* allow better default value in parameters using codegen property

* update
This commit is contained in:
William Cheng 2023-06-21 16:36:45 +08:00 committed by GitHub
parent 33aa5b07f3
commit d160b827de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2179,6 +2179,21 @@ public class DefaultCodegen implements CodegenConfig {
return toDefaultValue(schema);
}
/**
* Return the default value of the parameter
* <p>
* Return null if you do NOT want a default value.
* Any non-null value will cause {{#defaultValue} check to pass.
*
* @param codegenProperty Codegen Property
* @param schema Parameter schema
* @return string presentation of the default value of the parameter
*/
public String toDefaultParameterValue(CodegenProperty codegenProperty, Schema<?> schema) {
// by default works as original method to be backward compatible
return toDefaultParameterValue(schema);
}
/**
* Return property value depending on property type.
*
@ -5120,9 +5135,6 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter.isNullable = true;
}
// set default value
codegenParameter.defaultValue = toDefaultParameterValue(parameterSchema);
if (parameter.getStyle() != null) {
codegenParameter.style = parameter.getStyle().toString();
codegenParameter.isDeepObject = Parameter.StyleEnum.DEEPOBJECT == parameter.getStyle();
@ -5290,6 +5302,9 @@ public class DefaultCodegen implements CodegenConfig {
}
}
// set default value
codegenParameter.defaultValue = toDefaultParameterValue(codegenProperty, parameterSchema);
finishUpdatingParameter(codegenParameter, parameter);
return codegenParameter;
}
@ -6901,7 +6916,6 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter.baseType = codegenProperty.baseType;
codegenParameter.dataType = codegenProperty.dataType;
codegenParameter.defaultValue = toDefaultParameterValue(propertySchema);
codegenParameter.baseName = codegenProperty.baseName;
codegenParameter.paramName = toParamName(codegenParameter.baseName);
codegenParameter.dataFormat = codegenProperty.dataFormat;
@ -6912,6 +6926,9 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter._enum = codegenProperty._enum;
codegenParameter.allowableValues = codegenProperty.allowableValues;
// set default value
codegenParameter.defaultValue = toDefaultParameterValue(codegenProperty, propertySchema);
if (ModelUtils.isFileSchema(ps) && !ModelUtils.isStringSchema(ps)) {
// swagger v2 only, type file
codegenParameter.isFile = true;
@ -7046,7 +7063,10 @@ public class DefaultCodegen implements CodegenConfig {
imports.add(codegenProperty.complexType);
}
}
// set example value
setParameterExampleValue(codegenParameter);
// set nullable
setParameterNullable(codegenParameter, codegenProperty);