Fix bug where object schemas representing an allOf
type with more than one schema but only one property were inferred as the wrong type
#181
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
It's a bit of a mouthful, but we ran into an issue with a very specific schema definition:
The above schema describes two types, type
A
, which has a single property calledkind
which is aString
and typeFour
, which is actually identical toA
.It's a unique situation, but when we attempt to use
Four
in a polymorphic schema that uses a discriminator, it's type is incorrectly inferred as demonstrated in 0d04732:CreateAPI/Tests/Support/Specs/discriminator.yaml
Lines 81 to 98 in 0d04732
CreateAPI/Tests/Support/Snapshots/discriminator/Sources/Entities/AnotherContainer.swift
Lines 6 to 35 in 0d04732
Instead of the
AnotherContainer
type containing afour(Four)
case, it ends up withstring(String)
, which is absolutely not what we want.We traced it back to this code:
CreateAPI/Sources/CreateAPI/Generator/Generator+Schemas.swift
Lines 494 to 503 in da8730b
Changes
It's not entirely clear what the special Zoom code was trying to achieve, but when running CreateAPI against the Zoom API spec again, it turns out that the presence of this code makes no difference to the output. For that reason, I can only assume that it's now redundant and given that its presence causes a bug in other usage, we've decided to remove it.
If we do for some reason realise that we need this code back, it could always return as a vendor extension, but realistically I don't think that will happen. I'd also rather look into the exact motivation and figure out how to support that in other ways anyway.
After removing this code, I am able to generate the expected representation of
AnotherContainer
which is committed as part of this Pull Request.