fix: OAS 3.1 schema generation for raw Object properties#5034
fix: OAS 3.1 schema generation for raw Object properties#5034daniel-kmiecik merged 15 commits intoswagger-api:masterfrom
Conversation
|
@xeulbn please also check for errors in builds and code scanning jobs. |
|
Sorry I missed the comment before the build test. |
|
The build failure was caused by the updated OAS 3.1 handling for raw
I updated the OAS 3.1 expected output accordingly. Verified locally on JDK 17 with: All tests passed. |
|
Another build failure was caused by the updated OAS 3.1 handling for raw Object, which changes the expected YAML output in several OAS 3.1 test resources and reader tests. Empty object schemas are now consistently rendered as I updated the affected OAS 3.1 YAML expectations and reader tests accordingly. |
|
In OpenAPI 3.1, Previously, inferred types (e.g. While looking into this, I considered an explicit Tests were updated accordingly. |
|
@xeulbn thank you for your PR and for taking the time to contribute to the community. Your effort are truly appreciated! |
|
Thank you for the review and guidance throughout the process. I appreciate the detailed feedback — it helped me better understand the differences between OAS 3.0 and 3.1 schema handling. |
|
Hi, the changes introduced in this PR seem to conflict with what has previously controlled with the explicit setting "explicit-object-schema", which was introduced and described in #4868 (comment). Further, now a Map<String, Object> becomes "additionalProperties": {
"type": "object"
}Rather than the previous "additionalProperties": {}I can see from the tests that this is intentional. But to my knowledge this new schema expresses a new type of restriction on the request. For example the request "key": "value"Is now an invalid request, since So the addition of Would it be considered correct if I investigated how to best revert the change for a additionalProperties field? |
|
Thanks for raising this. I think that is a fair point. My intention with this change was to improve how raw That said, I agree
can indeed narrow the allowed values and change the schema semantics in a way that is closer to So I would not see this as invalidating the overall change, but I do think it makes sense to investigate reverting or refining the behavior specifically for |
Pull Request
Thank you for contributing to swagger-core!
Please fill out the following information to help us review your PR efficiently.
Description
Related issue: #4682
This PR fixes an issue in OpenAPI 3.1 schema generation where properties
declared as raw Java Object were rendered as an empty schema ({}).
In the OAS 3.1 path, PrimitiveType.OBJECT#createProperty31() returned an empty
JsonSchema without populating Schema#types. Since OpenAPI 3.1 relies on
JSON Schema semantics and uses types during serialization, the missing type
information caused the schema to be emitted as {}.
To resolve this, the OAS 3.1 schema generation for raw Object types has been
updated to explicitly set types = ["object"].
Additionally, regression tests have been added to cover:
ObjectpropertiesList<Object>item schemasMap<String, Object>additionalProperties schemasFixes: #4682
Type of Change
Checklist
Screenshots / Additional Context
The tests were executed locally with:
mvn -pl modules/swagger-core -Dtest=ObjectFieldOas31ReproTest testBefore (OAS 3.1)
After (OAS 3.1)