Skip to content

[Bug]: Example value starting with a number is parsed incorrectly #4999

@Sagr-gupta

Description

@Sagr-gupta

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:

Image

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.

openapi.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions