Skip to content

fix(resolver): handle recursive external JSON Schema refs#4222

Open
Richardpwe wants to merge 1 commit into
swagger-api:masterfrom
Richardpwe:master
Open

fix(resolver): handle recursive external JSON Schema refs#4222
Richardpwe wants to merge 1 commit into
swagger-api:masterfrom
Richardpwe:master

Conversation

@Richardpwe
Copy link
Copy Markdown

Description

This updates the $ref resolver so resolveSubtree terminates 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 $ref instead 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.json

Motivation and Context

Fixes #4221.

Recursive external JSON Schema references can currently cause resolveSubtree to keep expanding the same external refs until Swagger UI hangs or throws RangeError: 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.js
  • npm 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.js
  • npm run lint
  • git diff --check

Types of changes

  • No code changes (changes to documentation, CI, metadata, etc)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recursive external JSON Schema refs can overflow resolveSubtree

1 participant