fix: OAS 3.1 schema generation for raw Object properties is controlled with explicit-object-schema flag#5112
Merged
ewaostrowska merged 2 commits intoswagger-api:masterfrom Apr 14, 2026
Conversation
| @Override | ||
| public Schema createProperty31() { | ||
| return explicitObjectType == null || explicitObjectType ? new JsonSchema().typesItem("object") : new JsonSchema(); | ||
| return Boolean.TRUE.equals(explicitObjectType) ? new JsonSchema().typesItem("object") : new JsonSchema(); |
Contributor
Author
There was a problem hiding this comment.
This is the main change where null is changed from true to false
a693594 to
8141257
Compare
8141257 to
13cd478
Compare
| } | ||
|
|
||
| private boolean isExplicitObjectType() { | ||
| return openapi31 |
Contributor
There was a problem hiding this comment.
Just a small logic simplification here :)
941906b to
0caf290
Compare
ewaostrowska
approved these changes
Apr 14, 2026
…d with explicit-object-schema flag
0caf290 to
6f798d4
Compare
Contributor
|
Thank you @Mattias-Sehlstedt for taking you time to work on this issue and pushing small readability changes on the occasion as well! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Reverts changes from #5034 and restores the default resolving behavior for an OAS 3.1 Java
Objectto an empty type rather than typeobject.Adds tests to highlight that such a resolving logic should be achieved by setting the
explicit-object-schemaflag to true.OAS 3.1
In recent versions, raw Object values in OAS 3.1 were emitted as:
type: objectThis behavior has now been reverted.
For OAS 3.1, raw Object is again rendered as an empty schema by default:
{}This applies to:
Objectproperties,List<Object>item schemas andMap<String, Object>value schemas. In OpenAPI 3.1, Schema Objects follow JSON Schema semantics more closely. An empty schema means “any JSON value is allowed,” which is a better match for Java Object. Type: object means only JSON objects are allowed, which is too restrictive for raw Java Object, since it may also contain:strings,numbers,booleans,arrays,nullexplicit-object-schema
To force type: object to be generated:
explicit-object-schema=trueOAS 3.0
Behavior is unchanged.
type: objectis generated by default. This can be changed by explicitly setting
explicit-object-schema=falseFixes: #5111
Type of Change