Treat single element allOf/oneOf/anyOf schemas as the nested schema#39
Merged
liamnichols merged 6 commits intoCreateAPI:mainCreateAPI/CreateAPI:mainfrom Jun 10, 2022
liamnichols:ln/inlining-testsliamnichols/CreateAPI:ln/inlining-testsCopy head branch name to clipboard
Merged
Treat single element allOf/oneOf/anyOf schemas as the nested schema#39liamnichols merged 6 commits intoCreateAPI:mainCreateAPI/CreateAPI:mainfrom liamnichols:ln/inlining-testsliamnichols/CreateAPI:ln/inlining-testsCopy head branch name to clipboard
liamnichols merged 6 commits intoCreateAPI:mainCreateAPI/CreateAPI:mainfrom
liamnichols:ln/inlining-testsliamnichols/CreateAPI:ln/inlining-testsCopy head branch name to clipboard
Conversation
Member
Author
|
I have confirmed that this works as intended on a larger codebase too 👍 |
imjn
approved these changes
Jun 10, 2022
Member
imjn
left a comment
There was a problem hiding this comment.
The changes and the tests both look great to me 👍🏽 Thank you 🥇
48237df to
89dc184
Compare
…one object as if it was the object
6133682 to
36d9b3d
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
# Background
In our schema, we frequently do something like the following:
{ "type": "object", "required": [ "user" ], "properties": { "user": { "nullable": false, "allOf": [ { "$ref": "#/components/schemas/User" } ] } } }In the above example, the
userproperty needs to be nullable, but the schema of the property is actually a reference to a non-nullable component. The semi-official (but not ideal) way that was established to handle this case is to nest the$refin anallOf/anyOf/oneOfarray and mark it asnullable(you can't have other annotations alongside$ref).While this approach works in our Android code generator, and our server-side validator, it produces unexpected results in CreateAPI when using
isInliningPropertiesFromReferencedSchemasbecause CreateAPI will attempt to inline theallOfas a new type instead of referencing the actual type as an optional property.Changes
To reproduce the issue locally, I first needed to setup some test coverage since we hadn't tested it before now. To do that, I've added a new inlining.yml schema and setup a few scenarios that test this behaviour in general.
Finally, I applied the actual fix in 48237df