Fix parsing of schemas that are combinations of unnamed schemas and oneOf/allOf/... #566
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.
This is an attempt to fix the issue described in my comment here.
Basically, the issue arises when parsing a schema that is a combination of a
oneOf
/allOf
/... and an unnamed schema (see example below), for example, the output interface for the array items would completely ignore theproperties
part of the schema.This was due to the way how schema type matching was done. It would match only as
ONE_OF
and not a combination of[ONE_OF, UNNAMED_SCHEMA]
. If we would add an$id
to the definition, the schema would be parsed correctly as[ONE_OF, NAMED_SCHEMA]
.This PR attempts to fix this issue by changing how
UNNAMED_SCHEMA
is matched by adding an explicit condition. So far it was handled as: if nothing else matches, default toUNNAMED_SCHEMA
, which is why it never matched in scenarios described above.I've added two tests and updated several existing tests, since the new condition generates types that were previously missed.
Please check it out and let me know any improvement and if this is a valid solution in your opinion.
Thanks!
Example: