swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

fix: Treat example values starting with numbers as strings (#4999)

Open zero2top opened this issue 1 month ago • 1 comments

Pull Request

Thank you for contributing to swagger-core!

Description

This PR fixes an issue where example values that begin with a digit (e.g., "5 lacs per annum") are incorrectly parsed as a numeric literal instead of a string.

The root cause was that Json31.mapper().readTree(...) interprets any string that starts with a digit as JSON numeric content, resulting in the loss of the remaining string.

What this PR changes

Updated AnnotationsUtils#getSchemaFromAnnotation to ensure that example values beginning with digits are always treated as strings.

Added a test case testExampleStartingWithNumberShouldBeString to verify the expected behavior.

Fixes: #4999

Type of Change

  • Bug fix

  • Tests

Checklist

  1. I have added/updated tests as needed
  2. The PR title is descriptive
  3. The code builds and passes tests locally
  4. I have linked the related issue (#4999)

Example before the fix:

"example": 5

After the fix:

"example": "5 lacs per annum"

zero2top avatar Nov 21 '25 09:11 zero2top