Better error handling for toExampleValue (#8940)

* better error handling for toExampleValue

* revise logging

* update debug
This commit is contained in:
William Cheng 2021-03-15 17:54:15 +08:00 committed by GitHub
parent 5d7f1c1c88
commit bf859c640e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3103,7 +3103,14 @@ public class DefaultCodegen implements CodegenConfig {
property.title = p.getTitle();
property.getter = toGetter(name);
property.setter = toSetter(name);
property.example = toExampleValue(p);
// put toExampleValue in a try-catch block to log the error as example values are not critical
try {
property.example = toExampleValue(p);
} catch (Exception e) {
LOGGER.error("Error in generating `example` for the property {}. Default to ERROR_TO_EXAMPLE_VALUE. Enable debugging for more info.", property.baseName);
LOGGER.debug("Exception from toExampleValue: {}", e);
property.example = "ERROR_TO_EXAMPLE_VALUE";
}
property.defaultValue = toDefaultValue(p);
property.defaultValueWithParam = toDefaultValueWithParam(name, p);
property.jsonSchema = Json.pretty(p);