Don't generate inline schemas when allOf
only contains a single schema
#278
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 relates to the patch applied in #269, which in turn relates to #267. cc @nicholascross, @ymhuang0808. Firstly please excuse me if i missed some important historical context but I'm just trying to solve a slightly different regression that I noticed in some of my own examples.
In #269, we reintroduced inline generation for
allOf
types however in turn this introduced this diff: https://github.com/yonaskolb/SwagGen/pull/269/files#diff-6582636d47b022b95a7a5dfd79ff1e767f5f862e5eba00c00eb46208c5e7aab1I believe that this is separate to the original issue however since
Zoo.AllOfDog
andZoo.InlineAnimal
go unused and this is related to the issue that I am seeing with my schema.If we take the following:
The intention of the
last_error
property is to reference an existing schema (Error
) but to override its nullability and/or description when used withinUserSubclass
since its likely that these two properties on the schema (and possibly more) will vary. My understanding is that this approach is commonly used and i've seen other generators working with it.In fact, SwagGen was already properly resolving the property types to
Animal
andDog
as expected (hence why the inline types went unused) thanks to this:SwagGen/Sources/SwagGenKit/SwiftFormatter.swift
Lines 156 to 162 in 76d42a6
As a result, my change ensures that
inlineSchema
is only returned ifgroup.schemas.count > 1
and this means that the unusedLastError
inline type would be omitted again:Before
After
As for the original issue reported in #267, I updated TestSpec in c10a5e6 to include the expected results described by @ymhuang0808 (at least I think I did 😅) so hopefully the updated fixtures describe fixes to both issues... Please confirm though!
Thanks 🙇