better handling of const value

This commit is contained in:
William Cheng 2023-09-18 10:09:54 +08:00
parent 3b81c707b6
commit b52f6aa204

View File

@ -5365,7 +5365,17 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter.constant = toDefaultParameterValue(codegenProperty, enumSchema);
}
} else if (parameterSchema.getConst() != null) { // JSON Sschema keyword `const`
codegenParameter.constant = String.valueOf(parameterSchema.getConst());
Schema temp = null;
Pattern pattern = Pattern.compile("-?\\d+(\\.\\d+)?");
String constantValue = String.valueOf(parameterSchema.getConst());
if (pattern.matcher(constantValue).matches()) { // numeric constant value
temp = new NumberSchema();
temp.setDefault(constantValue);
} else { // constant value is a string
temp = new StringSchema();
temp.setDefault(constantValue);
}
codegenParameter.constant = toDefaultParameterValue(temp);
}
finishUpdatingParameter(codegenParameter, parameter);