Skip to content

Commit bf859c6

Browse files
authored
Better error handling for toExampleValue (#8940)
* better error handling for toExampleValue * revise logging * update debug
1 parent 5d7f1c1 commit bf859c6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3103,7 +3103,14 @@ public CodegenProperty fromProperty(String name, Schema p) {
31033103
property.title = p.getTitle();
31043104
property.getter = toGetter(name);
31053105
property.setter = toSetter(name);
3106-
property.example = toExampleValue(p);
3106+
// put toExampleValue in a try-catch block to log the error as example values are not critical
3107+
try {
3108+
property.example = toExampleValue(p);
3109+
} catch (Exception e) {
3110+
LOGGER.error("Error in generating `example` for the property {}. Default to ERROR_TO_EXAMPLE_VALUE. Enable debugging for more info.", property.baseName);
3111+
LOGGER.debug("Exception from toExampleValue: {}", e);
3112+
property.example = "ERROR_TO_EXAMPLE_VALUE";
3113+
}
31073114
property.defaultValue = toDefaultValue(p);
31083115
property.defaultValueWithParam = toDefaultValueWithParam(name, p);
31093116
property.jsonSchema = Json.pretty(p);

0 commit comments

Comments
 (0)