-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: OAS 3.1 schema generation for raw Object properties #5034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
daniel-kmiecik
merged 15 commits into
swagger-api:master
from
xeulbn:fix/oas31-object-schema
Feb 19, 2026
+121
−23
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1d08a90
Fix OAS 3.1 schema generation for raw Object properties
xeulbn ed7b980
Merge branch 'master' into fix/oas31-object-schema
daniel-kmiecik ce98811
Merge branch 'master' into fix/oas31-object-schema
daniel-kmiecik 8840ed2
Merge branch 'master' into fix/oas31-object-schema
daniel-kmiecik 056a53e
Align OAS 3.1 Object schema handling with OAS 3.0 behavior
xeulbn 2bb2945
Rename OAS 3.1 Object schema tests to follow naming conventions
xeulbn 6910d3a
Fix OAS 3.1 object schema test expectations
xeulbn f5636c5
Align OAS31 YAML fixtures with type: object for Object
xeulbn 3358fd1
Merge branch 'master' into fix/oas31-object-schema
daniel-kmiecik b245bc6
Update OAS31 object schema expectations
xeulbn c7c15e7
OAS 3.1: prefer explicit schema types over inferred ones
xeulbn a4a6793
Update OAS 3.1 test expectations for explicit types
xeulbn 689be85
Merge branch 'master' into fix/oas31-object-schema
daniel-kmiecik bb652d1
Remove setType usage in OAS 3.1 schema resolution
xeulbn 07debc6
Remove setType usage in OAS 3.1 annotations
xeulbn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
91 changes: 91 additions & 0 deletions
91
...les/swagger-core/src/test/java/io/swagger/v3/core/serialization/Oas31ObjectFieldTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package io.swagger.v3.core.serialization; | ||
|
|
||
| import io.swagger.v3.core.converter.ModelConverters; | ||
| import io.swagger.v3.oas.models.media.Schema; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class Oas31ObjectFieldTest { | ||
| @Test(description = "Repro #4682: In OAS 3.1, raw Object property should not be rendered as an empty schema") | ||
| public void rawObjectPropertyShouldBeObjectSchema() { | ||
| Map<String, Schema> schemas = ModelConverters.getInstance(true).readAll(PojoUsingObjectField.class); | ||
| Schema pojo = schemas.get("PojoUsingObjectField"); | ||
| Assert.assertNotNull(pojo, "PojoUsingObjectField schema should exist"); | ||
|
|
||
| Schema myField = (Schema) pojo.getProperties().get("myField"); | ||
| Assert.assertNotNull(myField, "myField schema should exist"); | ||
| Assert.assertTrue(isObjectSchema(myField), "Expected raw Object property to be an object schema in OAS 3.1, but was: type=" + myField.getType() + ", types=" + myField.getTypes() + ", class=" + myField.getClass()); | ||
| } | ||
|
|
||
| @Test(description = "OAS 3.1: List<Object> items schema should be object") | ||
| public void listOfObjectItemsShouldBeObjectSchema() { | ||
| Map<String, Schema> schemas = ModelConverters.getInstance(true).readAll(PojoUsingListOfObject.class); | ||
| Schema pojo = schemas.get("PojoUsingListOfObject"); | ||
| Assert.assertNotNull(pojo, "PojoUsingListOfObject schema should exist"); | ||
| Schema itemsProp = (Schema) pojo.getProperties().get("items"); | ||
| Assert.assertNotNull(itemsProp, "items property schema should exist"); | ||
| Schema itemSchema = itemsProp.getItems(); | ||
| Assert.assertNotNull(itemSchema, "List<Object> items schema should exist"); | ||
| Assert.assertTrue(isObjectSchema(itemSchema), "Expected List<Object> items to be an object schema in OAS 3.1, but was: type=" + itemSchema.getType() + ", types=" + itemSchema.getTypes() + ", class=" + itemSchema.getClass()); | ||
| } | ||
|
|
||
| @Test(description = "OAS 3.1: Map<String,Object> additionalProperties schema should be object") | ||
| public void mapOfObjectAdditionalPropertiesShouldBeObjectSchema() { | ||
| Map<String, Schema> schemas = ModelConverters.getInstance(true).readAll(PojoUsingMapStringToObject.class); | ||
| Schema pojo = schemas.get("PojoUsingMapStringToObject"); | ||
| Assert.assertNotNull(pojo, "PojoUsingMapStringToObject schema should exist"); | ||
| Schema additionalProp = (Schema) pojo.getProperties().get("additional"); | ||
| Assert.assertNotNull(additionalProp, "additional property schema should exist"); | ||
| Schema valueSchema = (Schema) additionalProp.getAdditionalProperties(); | ||
| Assert.assertNotNull(valueSchema, "Map<String,Object> additionalProperties (value schema) should exist"); | ||
| Assert.assertTrue(isObjectSchema(valueSchema), "Expected Map<String,Object> additionalProperties to be an object schema in OAS 3.1, but was: type=" + valueSchema.getType() + ", types=" + valueSchema.getTypes() + ", class=" + valueSchema.getClass()); | ||
| } | ||
|
|
||
| /** | ||
| * OAS 3.1 may represent types via Schema#getTypes() (JSON Schema style) rather than Schema#getType(). | ||
| */ | ||
| private static boolean isObjectSchema(Schema s) { | ||
| if (s == null) return false; | ||
| if ("object".equals(s.getType())) return true; | ||
| return s.getTypes() != null && s.getTypes().contains("object"); | ||
| } | ||
|
|
||
| private static class PojoUsingObjectField { | ||
| private Object myField; | ||
|
|
||
| public Object getMyField() { | ||
| return myField; | ||
| } | ||
|
|
||
| public void setMyField(Object myField) { | ||
| this.myField = myField; | ||
| } | ||
| } | ||
|
|
||
| private static class PojoUsingListOfObject { | ||
| private List<Object> items; | ||
|
|
||
| public List<Object> getItems() { | ||
| return items; | ||
| } | ||
|
|
||
| public void setItems(List<Object> items) { | ||
| this.items = items; | ||
| } | ||
| } | ||
|
|
||
| private static class PojoUsingMapStringToObject { | ||
| private Map<String, Object> additional; | ||
|
|
||
| public Map<String, Object> getAdditional() { | ||
| return additional; | ||
| } | ||
|
|
||
| public void setAdditional(Map<String, Object> additional) { | ||
| this.additional = additional; | ||
| } | ||
| } | ||
| } |
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.