Repository navigation
[java] fix: okhttp-gson additionalProperties field makes every allOf child undeserializable #24895
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
wing328
merged 9 commits into
OpenAPITools:master
from
wiebren:fix/java-additional-properties-transient
Oct 5, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eb98f3c
[java] fix: the okhttp-gson additionalProperties bag breaks every all…
wiebren 20b5c48
[java] fix: keep the bag visible on parents that have no adapter of t…
wiebren 2b160d6
[java] docs: describe gson's field binding accurately
wiebren 6383715
[java] fix: declare the okhttp-gson bag once per allOf hierarchy
wiebren 71d55db
[java] fix: round-trip a literal additionalProperties key on allOf ch…
wiebren ca4e648
test: [java] record the new checksum of the okhttp-gson JSONTest
wiebren 1f02ca7
[java] fix: hide a literal additionalProperties key from the okhttp-g…
wiebren 7f46896
[java] refactor: drop transient and the literal-key handling from the…
wiebren 0cbbdf4
test: [java] round-trip an allOf child's additional properties in the…
wiebren 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
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
33 changes: 33 additions & 0 deletions
33
...-generator/src/test/resources/3_0/java/okhttp-gson-additional-properties-allof-chain.yaml
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,33 @@ | ||
| openapi: 3.0.3 | ||
| info: {title: t, version: '1'} | ||
| paths: | ||
| /c: | ||
| get: | ||
| responses: | ||
| '200': | ||
| description: ok | ||
| content: | ||
| application/json: | ||
| schema: {$ref: '#/components/schemas/Leaf'} | ||
| components: | ||
| schemas: | ||
| Root: | ||
| type: object | ||
| required: [kind] | ||
| discriminator: {propertyName: kind} | ||
| properties: | ||
| kind: {type: string} | ||
| a: {type: string} | ||
| Middle: | ||
| allOf: | ||
| - $ref: '#/components/schemas/Root' | ||
| - type: object | ||
| properties: | ||
| b: {type: string} | ||
| discriminator: {propertyName: kind} | ||
| Leaf: | ||
| allOf: | ||
| - $ref: '#/components/schemas/Middle' | ||
| - type: object | ||
| properties: | ||
| c: {type: string} |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: This read path now delegates
jsonObjdirectly to the reflective adapter, which re-exposes a literaladditionalPropertieskey to the inherited bag. Because the bag is declared once on the topmost ancestor and is no longertransient, the child'sthisAdapter.fromJsonTreebinds a literaladditionalPropertieskey straight into the inheritedMap<String, Object>field: non-object values (number, array, string, boolean) make Gson throw during deserialization, and object values are double-stored (the delegate fills the map, then the unchanged loop below callsputAdditionalProperty("additionalProperties", …)again), so the bag and the round-trip output gain spurious keys. This contradicts the PR goal, which calls for dropping the key before delegating so round-trips preserve the key once; the added JSONTest only exercises plain undeclared keys like"extra", so it does not cover this. Restore thedelegateObjdeep copy +remove("additionalProperties")beforethisAdapter.fromJsonTreefor models withx-inherits-additional-properties.Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the known gap the description lists: a literal
additionalPropertiesJSON key holding a non-object value throws when gson's reflective delegate binds it to the bag field. It is not new to this PR. On master every model that declares the bag behaves the same way, because the field is visible to reflection there too; this PR keeps allOf children on that same behaviour instead of failing on the duplicate field. Fixing it for all models belongs in its own change.