GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||
GeezerVison is showing github.com — fix: keep oneOf when WRAPPER_OBJECT wrapping is applied by vpelikh · Pull Request #5331 · swagger-api/swagger-core Conversation
|
| result | |
|---|---|
| before | ObjectSchema, properties [Pet], no oneOf |
| after | ComposedSchema, oneOf = 2 refs, wrapper property present |
When the model already has a non-empty oneOf, add the wrapper property directly to the model and return it, instead of nesting it in a wrapper schema:
if (model.getOneOf() != null && !model.getOneOf().isEmpty()) { model.addProperties(name, newObjectSchema()); return model; }
The empty-object-schema expression was already used once in this method, so instead of repeating it a second time it is extracted to a small helper:
/** An empty object schema for the current OpenAPI version. */ private Schema newObjectSchema() { return openapi31 ? new JsonSchema().typesItem("object") : new ObjectSchema(); }
Behavior is unchanged for models without oneOf.
Adds WrapperObjectOneOfTest. It fails before the change (ObjectSchema with no oneOf) and passes after it.
This is the small stack split out of #5320. It is a standalone bug fix, reproducible on unmodified 3.0.0, and does not depend on @JsonSubTypes work.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thank you for the PR @vpelikh! I tested this and pushed a small change on top: I removed the empty placeholder property, because it added noise to the schema. I also added tests (no extra property next to Before the PR, Pet: type: object properties: Pet: type: object properties: petType: {type: string} oneOf: [Dog, Cat] After the PR, as submitted: Pet: type: object properties: petType: {type: string} Pet: {type: object} # empty placeholder oneOf: [Dog, Cat] The The schema is still not fully correct. With {"Dog": {"petType": "dog", "bark": "woof"}}To match it, each Pet: oneOf: - type: object required: [Dog] properties: Dog: {$ref: '#/components/schemas/Dog'} - type: object required: [Cat] properties: Cat: {$ref: '#/components/schemas/Cat'} That needs a more complex handler (subtype names, |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hey @ewaostrowska. Thanks for reviewing this and other PRs. Are you okay with this PR as is, or would you like me to make some changes? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
a7bcd87 to
a5ecee0
Compare
|
@vpelikh I think the current state should be fine for now, but let's wait on review from @djankows or @daniel-kmiecik |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The implementation preserves oneOf by removing required WRAPPER_OBJECT semantics, producing a schema that does not match serialized values.
Attempts to preserve oneOf schemas during Jackson WRAPPER_OBJECT resolution.
Changes:
oneOf is present.| File | Description |
|---|---|
ModelResolver.java |
Alters wrapping behavior for composed schemas. |
WrapperObjectOneOfTest.java |
Tests oneOf preservation and repeated resolution. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
ModelResolver.resolveWrapping() nested the whole model inside a new wrapper schema that only copied the name and properties, so a model carrying a oneOf (from @Schema(oneOf) or @JsonSubTypes) lost its composition and became a plain object schema with a single property. When the model already has a non-empty oneOf, add the wrapper property directly to the model and return it, preserving the composition. Behavior is unchanged for models without oneOf. Adds WrapperObjectOneOfTest, which fails before the fix (ObjectSchema with no oneOf) and passes after it.
a5ecee0 to
fdce351
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.