fix: keep polymorphic subtype composition when re-resolved standalone (#5028)#5230
Open
seonwooj0810 wants to merge 1 commit into
Open
Conversation
A subtype's allOf reference to its parent is built by the parent's resolveSubtypes and stored via defineModel. When the same subtype is later resolved standalone (e.g. while resolving a discriminatorMapping target, which uses an AnnotatedType without the subtype flag and so misses the resolution cache since swagger-api#4975/swagger-api#5005), the plain re-resolution overwrote the stored composed schema, dropping its allOf. Guard model registration so a schema without composition keywords never overwrites an already-registered composed schema of the same name. Fixes swagger-api#5028 Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>
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.
Fixes #5028
Root cause
Polymorphic subtypes lose their
allOfreference to the parent (regression in 2.2.41): a subtype that resolved todegrades to
{ "type": "object", "properties": {} }.The parent's
resolveSubtypesbuilds each subtype's composed schema (allOf→ parent) and registers it viadefineModel. However, when the same subtype is resolved standalone afterwards — here while resolving the parent's@DiscriminatorMapping, whoseresolveDiscriminatorcallscontext.resolve(new AnnotatedType().type(mapping.schema()))without thesubtype(true)flag — the resolution-cache lookup misses (AnnotatedTypeequality was tightened in #4975 / #5005), so the subtype is re-resolved as a plain object andmodelByNameis overwritten, dropping the composition.Fix
Guard model registration in
ModelConverterContextImplso a schema without composition keywords (allOf/anyOf/oneOf) never overwrites an already-registered composed schema of the same name. The forward direction (plain → composed) is unaffected, so the composed subtype definition survives the later plain re-resolution. Applied at both storage sites (defineModeland theresolve()name mapping).Tests
Added
Ticket5028Testreproducing the reporter's hierarchy (interface parent withsubTypes+discriminatorMapping, subtype via@Schema(implementation=...)). Both assertions fail on master and pass with the fix, for OpenAPI 3.0 and 3.1.Verification done
resolveDiscriminatorL2746 →ModelConverterContextImpl.resolve/defineName).swagger-coremodule suite (722 tests) + focused composition/subtype/discriminator suite (38 tests) pass with the change.git commit -s(DCO).