fix: Treat example values starting with numbers as strings (#4999)
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
- I have added/updated tests as needed
- The PR title is descriptive
- The code builds and passes tests locally
- I have linked the related issue (#4999)
Example before the fix:
"example": 5
After the fix:
"example": "5 lacs per annum"