fix(resolver): handle recursive external JSON Schema refs#4222
Open
Richardpwe wants to merge 1 commit into
Open
fix(resolver): handle recursive external JSON Schema refs#4222Richardpwe wants to merge 1 commit into
Richardpwe wants to merge 1 commit into
Conversation
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.
Description
This updates the
$refresolver soresolveSubtreeterminates safely when resolving recursive external JSON Schema references.The resolver now tracks fully qualified refs in the current resolution context. If the same external ref appears again on that path, resolution stops at that boundary and preserves the
$refinstead of expanding recursively until the stack overflows.A regression test was added for a recursive external schema shape similar to:
object.json -> basic-types.json -> object.jsonMotivation and Context
Fixes #4221.
Recursive external JSON Schema references can currently cause
resolveSubtreeto keep expanding the same external refs until Swagger UI hangs or throwsRangeError: Maximum call stack size exceeded.This can happen with valid recursive JSON Schema documents, for example when an object schema references basic types and nested object/array schemas reference the object schema again.
How Has This Been Tested?
Added a focused regression test for recursive external JSON Schema refs in
resolveSubtree.Ran:
npm run test:unit -- --runTestsByPath test/subtree-resolver/strategies/openapi-2--3-0.jsnpm run test:unit -- --runTestsByPath test/resolver/index.js test/resolver/specmap/index.js test/resolver/specmap/lib.js test/resolver/specmap/refs.js test/subtree-resolver/strategies/openapi-2--3-0.jsnpm run lintgit diff --checkTypes of changes
package.json)Checklist: