forked from loafle/openapi-generator-original
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:
parent
33aa5b07f3
commit
d160b827de
@ -2179,6 +2179,21 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
return toDefaultValue(schema);
|
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.
|
* Return property value depending on property type.
|
||||||
*
|
*
|
||||||
@ -5120,9 +5135,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
codegenParameter.isNullable = true;
|
codegenParameter.isNullable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set default value
|
|
||||||
codegenParameter.defaultValue = toDefaultParameterValue(parameterSchema);
|
|
||||||
|
|
||||||
if (parameter.getStyle() != null) {
|
if (parameter.getStyle() != null) {
|
||||||
codegenParameter.style = parameter.getStyle().toString();
|
codegenParameter.style = parameter.getStyle().toString();
|
||||||
codegenParameter.isDeepObject = Parameter.StyleEnum.DEEPOBJECT == parameter.getStyle();
|
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);
|
finishUpdatingParameter(codegenParameter, parameter);
|
||||||
return codegenParameter;
|
return codegenParameter;
|
||||||
}
|
}
|
||||||
@ -6901,7 +6916,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
codegenParameter.baseType = codegenProperty.baseType;
|
codegenParameter.baseType = codegenProperty.baseType;
|
||||||
codegenParameter.dataType = codegenProperty.dataType;
|
codegenParameter.dataType = codegenProperty.dataType;
|
||||||
codegenParameter.defaultValue = toDefaultParameterValue(propertySchema);
|
|
||||||
codegenParameter.baseName = codegenProperty.baseName;
|
codegenParameter.baseName = codegenProperty.baseName;
|
||||||
codegenParameter.paramName = toParamName(codegenParameter.baseName);
|
codegenParameter.paramName = toParamName(codegenParameter.baseName);
|
||||||
codegenParameter.dataFormat = codegenProperty.dataFormat;
|
codegenParameter.dataFormat = codegenProperty.dataFormat;
|
||||||
@ -6912,6 +6926,9 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
codegenParameter._enum = codegenProperty._enum;
|
codegenParameter._enum = codegenProperty._enum;
|
||||||
codegenParameter.allowableValues = codegenProperty.allowableValues;
|
codegenParameter.allowableValues = codegenProperty.allowableValues;
|
||||||
|
|
||||||
|
// set default value
|
||||||
|
codegenParameter.defaultValue = toDefaultParameterValue(codegenProperty, propertySchema);
|
||||||
|
|
||||||
if (ModelUtils.isFileSchema(ps) && !ModelUtils.isStringSchema(ps)) {
|
if (ModelUtils.isFileSchema(ps) && !ModelUtils.isStringSchema(ps)) {
|
||||||
// swagger v2 only, type file
|
// swagger v2 only, type file
|
||||||
codegenParameter.isFile = true;
|
codegenParameter.isFile = true;
|
||||||
@ -7046,7 +7063,10 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
imports.add(codegenProperty.complexType);
|
imports.add(codegenProperty.complexType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set example value
|
||||||
setParameterExampleValue(codegenParameter);
|
setParameterExampleValue(codegenParameter);
|
||||||
|
|
||||||
// set nullable
|
// set nullable
|
||||||
setParameterNullable(codegenParameter, codegenProperty);
|
setParameterNullable(codegenParameter, codegenProperty);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user