Skip to content

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
Mattias-Sehlstedt:java-object-is-only-set-to-type-object-if-flag-is-true
Apr 14, 2026
Merged

fix: OAS 3.1 schema generation for raw Object properties is controlled with explicit-object-schema flag#5112
ewaostrowska merged 2 commits intoswagger-api:masterfrom
Mattias-Sehlstedt:java-object-is-only-set-to-type-object-if-flag-is-true

Conversation

@Mattias-Sehlstedt
Copy link
Copy Markdown
Contributor

@Mattias-Sehlstedt Mattias-Sehlstedt commented Apr 4, 2026

Description

Reverts changes from #5034 and restores the default resolving behavior for an OAS 3.1 Java Object to an empty type rather than type object.

Adds tests to highlight that such a resolving logic should be achieved by setting the explicit-object-schema flag to true.

OAS 3.1

In recent versions, raw Object values in OAS 3.1 were emitted as:
type: object

This behavior has now been reverted.

For OAS 3.1, raw Object is again rendered as an empty schema by default:

{}

This applies to: Object properties, List<Object> item schemas and Map<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, null

explicit-object-schema

To force type: object to be generated:

explicit-object-schema=true

OAS 3.0

Behavior is unchanged.

type: object

is generated by default. This can be changed by explicitly setting explicit-object-schema=false


Fixes: #5111

Type of Change

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

@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();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change where null is changed from true to false

@Mattias-Sehlstedt Mattias-Sehlstedt force-pushed the java-object-is-only-set-to-type-object-if-flag-is-true branch 2 times, most recently from a693594 to 8141257 Compare April 7, 2026 19:30
@ewaostrowska ewaostrowska force-pushed the java-object-is-only-set-to-type-object-if-flag-is-true branch from 8141257 to 13cd478 Compare April 13, 2026 09:54
}

private boolean isExplicitObjectType() {
return openapi31
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small logic simplification here :)

@ewaostrowska ewaostrowska force-pushed the java-object-is-only-set-to-type-object-if-flag-is-true branch 2 times, most recently from 941906b to 0caf290 Compare April 14, 2026 09:35
@ewaostrowska ewaostrowska force-pushed the java-object-is-only-set-to-type-object-if-flag-is-true branch from 0caf290 to 6f798d4 Compare April 14, 2026 12:52
@ewaostrowska ewaostrowska merged commit a252004 into swagger-api:master Apr 14, 2026
7 checks passed
@ewaostrowska
Copy link
Copy Markdown
Contributor

Thank you @Mattias-Sehlstedt for taking you time to work on this issue and pushing small readability changes on the occasion as well!

@Mattias-Sehlstedt Mattias-Sehlstedt deleted the java-object-is-only-set-to-type-object-if-flag-is-true branch April 14, 2026 18:11
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]: A Java raw Object is always resolved to OAS 3.1 object

2 participants