fix(reference): skip transcluded Example value in mutual-exclusion check#5191
Open
maruthang wants to merge 1 commit into
Open
fix(reference): skip transcluded Example value in mutual-exclusion check#5191maruthang wants to merge 1 commit into
maruthang wants to merge 1 commit into
Conversation
When a Path Item Object is referenced with $ref from an external document, the referenced fragment is dereferenced by a nested visitor and the merged result is traversed again by the outer visitor. Example Objects transcluded from externalValue intentionally contain both value and externalValue fields, so the second traversal raised a false positive "ExampleElement value and externalValue fields are mutually exclusive." error. The value element transcluded from externalValue is annotated with ref-origin meta, so already dereferenced Example Objects are now skipped. Fixes swagger-api/swagger-ui#10418
17 tasks
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 #5190. Also the root cause of swagger-api/swagger-ui#10418 (and the motivation behind the now-closed swagger-api/swagger-ui#10822, per @glowcloud's review there).
Problem
When an Example Object with only
externalValuesits inside an externally referenced Path Item Object, dereferencing fails with:The
PathItemElementhandler dereferences the external fragment with a nested visitor, thenlink.replaceWiths the merged Path Item — and the outer visitor descends into the already-dereferenced subtree. The nested pass has by then transcludedexternalValueintovalue(annotatingvaluewithref-originmeta) while intentionally keepingexternalValue, so the outer pass re-visits an Example that now has both fields and trips the mutual-exclusion guard. Without the path-level$refthere is only one traversal, hence no error.Fix
In the
ExampleElementhandlers of the 3.0, 3.1, and 3.2 dereference strategies, skip elements whosevaluecarries theref-originmeta (i.e. the value was already transcluded by a previous pass) before applying the mutual-exclusion check. A genuine violation (bothvalueandexternalValuein source) still errors as before.Verification
@swagger-api/apidom-reference@1.11.3; with this guard applied the repro dereferences cleanly and the output is identical to the inline (no-$ref) equivalent.external-value-path-item-refto the example-object dereference suites for the 3.0 and 3.1 strategies.