This repository was archived by the owner on Nov 8, 2024. It is now read-only.
Prevent treating overlapping paths as a circular reference #641
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.
A check that a reference to
#/definitions/User
from within#/definitions/UserList
would incorrectly been interpreted as a circular reference as a simplistic check that the current path starts with the current reference. We should ensure that the reference is either identical, or relative from another (such as with a trailing slash).This was easiest to test at a unit level so I have added unit tests for this method. The top 4 added tests would already pass, just increasing test coverage to account for all the branches in the circular reference checker.
To aid review, the circular reference checker is passed all the references we've traversed (this is the first argument). If we would follow a series of references (such as if we are currently at
#/definitions/Comment
#/items
, and then we followed a reference to#/definitions/User
which inside#/definitions/User/properties/comments/items
referenced. The current path would become
#/definitions/Commentand the current traversed path would be something like
['#/items', '#/definitions/User', '#/definitions/User/properties/comments/items']`. These parts of the current resolution are pushed and popped as we resolve a schema.