Repository navigation
Conversation
…l ref resolution ExternalRefProcessor.processSchema queried a map keyed by discriminator value with the member's original $ref, so the lookup always returned null: a null key was put into the mapping and the real entries were left unresolved (regression introduced while fixing swagger-api#2222). Index the mapping by ref -> discriminator values instead, so that several values can map to the same schema and the lookup by the original $ref works again. SchemaProcessor.changeDiscriminatorMapping rewrote only the first mapping entry pointing at a resolved ref; rewrite all of them. Add Issue2406Test with external file refs in a oneOf nested in array items and two discriminator values mapping to the same schema.
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.
Pull Request
Description
ExternalRefProcessor.processSchemaupdates thediscriminator.mappingof a composed schema that is nested in another schema (arrayitems, properties,additionalProperties) after the external$refs of itsoneOf/anyOfmembers have been rewritten. Since #2249 the lookup map is keyed by discriminator value, but it is queried with the member's original$ref, sorefMap.get(...)is alwaysnullandmapping.put(null, newRef)is executed for every rewritten member. The result is anullkey in the mapping and mapping values that are never updated (see #2406 for a reproducer and the history: #2087 introduced the block with the map inverted, which worked but threwDuplicate keywhen several values map to the same schema, #2222).This change indexes the mapping in
ExternalRefProcessoras ref -> list of discriminator values, so that$refworks again and the mapping values are rewritten together with theoneOf/anyOfrefs,Duplicate key ./TypeB.yamlfor the test spec below),nullkey can be inserted: members without a mapping entry are simply skipped.SchemaProcessor.changeDiscriminatorMapping, which later rewrites the root-relative paths produced by the first pass to#/components/schemas/..., only updated the first mapping entry pointing at the resolved ref; it now updates all of them, otherwise the second value mapping to the same schema stayed unresolved.Behaviour for local
#/components/schemas/...refs is unchanged (they are not rewritten and never enter either loop).Fixes: #2406
Type of Change
Checklist
Screenshots / Additional Context
Issue2406Testuses external file refs in aoneOfnested in arrayitems, with two discriminator values mapping to the same schema. Onmasterit fails (Unable to load RELATIVE ref: ./TypeA.yamlis reported, the mapping keepsa -> ./TypeA.yamletc. and gets anullkey):With this change the resolved document has no messages and:
Issue2222Test(local refs) andOpenAPIV3RefTest#testDiscriminatorMappingRefsUpdatedstill pass.