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

fix: resolve PrimitiveType casting for OpenAPI 3.1 schemas (#4963)

Open K5qu4r3d opened this issue 6 months ago • 1 comments

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, their createProperty31() method sets the value for only field type and not types.

Solution

Updated createProperty31() to set a value for field types. A new test class APIResponsesResourceTest verifies that the resulting schema's type and types field values match for each class defined in @Schema(implementation = ...).

Relevant issue

Fixes: #4963

Type of Change

  • [x] 🐛 Bug fix
  • [ ] ✨ New feature
  • [ ] ♻️ Refactor (non-breaking change)
  • [x] 🧪 Tests
  • [ ] 📝 Documentation
  • [ ] 🧹 Chore (build or tooling)

Checklist

  • [x] I have added/updated tests as needed
  • [ ] I have added/updated documentation where applicable
  • [x] The PR title is descriptive
  • [x] The code builds and passes tests locally
  • [x] I have linked related issues (if any)

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

K5qu4r3d avatar Oct 07 '25 19:10 K5qu4r3d

There are still some failing tests in APIResponsesResourceTest.java. Please adjust tests :)

ewaostrowska avatar Nov 12 '25 13:11 ewaostrowska