fix: resolve PrimitiveType casting for OpenAPI 3.1 schemas (#4963) #4989
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request
Thank you for contributing to swagger-core!
Please fill out the following information to help us review your PR efficiently.
Description
This PR fixes an issue where
PrimitiveType
OpenAPI 3.1 schemas used in@ApiResponse
content schema implementations are incorrectly cast to type"string"
instead of properly-defined types.Problem
For each enum in
PrimitiveType
, theircreateProperty31()
method sets the value for only fieldtype
and nottypes
.Solution
Updated
createProperty31()
to set a value for fieldtypes
. A new test classAPIResponsesResourceTest
verifies that the resulting schema'stype
andtypes
field values match for each class defined in@Schema(implementation = ...)
.Relevant issue
Fixes: #4963
Type of Change
Checklist
Screenshots / Additional Context
Added files:
modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/resources/APIResponsesResource.java
modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/APIResponsesResourceTest.java
Affected files:
modules/swagger-core/src/main/java/io/swagger/v3/core/util/AnnotationsUtils.java
modules/swagger-core/src/main/java/io/swagger/v3/core/util/PrimitiveType.java
modules/swagger-java17-support/src/test/java/io/swagger/v3/java17/resolving/v31/ModelResolverOAS31Test.java
modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/Ticket2992Test.java