Skip to content

Conversation

@zero2top
Copy link

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 ([Bug]: Example value starting with a number is parsed incorrectly #4999)

Example before the fix:

"example": 5

After the fix:

"example": "5 lacs per annum"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant