-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Description
When an example in an OpenAPI annotation (e.g., @Schema(example = "5 lacs per annum")) starts with a number, it appears that Swagger Core interprets the value as a numeric literal because the example begins with a digit. This results in the example being serialized as a number instead of a string.
For instance :
@Schema(example = "5 lacs per annum") private String salary;
In the generated OpenAPI schema, the example becomes:
"example": 5
instead of :
"example": "5 lacs per annum"
Where the issue occurs
The issue originates from the following code in io.swagger.v3.core.util.AnnotationsUtils#getSchemaFromAnnotation:
Because Json31.mapper().readTree(...) interprets any string starting with a digit as JSON numeric content,
the portion "lacs per annum" is ignored and only the number 5 is retained.
Affected Version
swagger-core-jakarta: 2.2.36
springdoc-openapi: 2.8.13
For reproducing the issue below I have attached a demo project. Kindly take reference.