Skip to content

Fix: primitive boxed type schemas incorrectly cast to "string" in OAS 3.1 #4963 - #4989

Merged
ewaostrowska merged 39 commits into
swagger-api:masterfrom
K5qu4r3d:bug/4963-fix-schema-primitive-boxed-type-cast
Aug 31, 2026
Merged

Fix: primitive boxed type schemas incorrectly cast to "string" in OAS 3.1 #4963#4989
ewaostrowska merged 39 commits into
swagger-api:masterfrom
K5qu4r3d:bug/4963-fix-schema-primitive-boxed-type-cast

Conversation

@K5qu4r3d

@K5qu4r3d K5qu4r3d commented Oct 7, 2025

Copy link
Copy Markdown
Contributor

Pull Request

Fixes: #4963

When generating OpenAPI 3.1 specs, @ApiResponse annotations that reference primitive boxed types (e.g. Boolean.class) as schema implementations produce a schema where the OAS 3.1 types set is correctly populated but type is then overwritten to "string". This causes invalid specs and incorrect client generation.


What was broken

AnnotationsUtils falls back to setType("string") when a schema has no $ref and no type. It did not check getTypes(), so OAS 3.1 schemas that already had the correct types set were silently clobbered.

What changed

  • AnnotationsUtils.java: added a doesSchemaHaveNullOrEmptyTypes guard to the setType("string") fallback so schemas already carrying an OAS 3.1 types value are not overwritten.

Type of Change

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

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • 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

Comment thread modules/swagger-core/src/main/java/io/swagger/v3/core/util/PrimitiveType.java Outdated
Comment thread modules/swagger-core/src/main/java/io/swagger/v3/core/util/PrimitiveType.java Outdated
Comment thread modules/swagger-core/src/main/java/io/swagger/v3/core/util/AnnotationsUtils.java Outdated
Comment thread modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/ReaderTest.java Outdated
@ewaostrowska
ewaostrowska force-pushed the bug/4963-fix-schema-primitive-boxed-type-cast branch 2 times, most recently from 15665a4 to 13e287a Compare November 12, 2025 13:08
@ewaostrowska
ewaostrowska force-pushed the bug/4963-fix-schema-primitive-boxed-type-cast branch from 5af7e9b to 47009dd Compare November 12, 2025 13:16
@ewaostrowska

Copy link
Copy Markdown
Contributor

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

@ewaostrowska

Copy link
Copy Markdown
Contributor

Hi @K5qu4r3d!
The fix in the AnnotationsUtils.java seems to be minimal and correct - the check on the types which is OAS 3.1 specific has been missing and adding it should restore setting the right types for this version of specification.
I have rolled back all the changes in PrimitiveType.class since :

@ewaostrowska ewaostrowska changed the title fix: resolve PrimitiveType casting for OpenAPI 3.1 schemas (#4963) Fix: primitive boxed type schemas incorrectly cast to "string" in OAS 3.1 #4963 Aug 31, 2026
@ewaostrowska
ewaostrowska merged commit a3e35e3 into swagger-api:master Aug 31, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Primitive boxed type schemas used in @ApiResponse content schema implementations are incorrectly cast to string

4 participants