-
-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem in paths reported for rule violations involving schema references within oneOf #2059
Comments
Offering a +1 to this issue, as it is quite a significant deviation from expected behavior. I think the root of the issue is the buggy path resolution logic - if it were reporting the correctly "decoded" paths, the de-duplication logic would filter out the extra result. As such, it may be related (or at least, is very similar) to #2043. |
It turns out that this issue also occurs if the schema ref is in an array schema's "items" field. To reproduce this, make the following changes to api.yaml within the testcase mentioned above:
Note that the items field within the "Drinks" schema is a ref to the "Drink" schema. |
After debugging the spectral code a bit for this issue, I think the problem occurs inside the |
@P0lip any chance that someone with detailed knowledge of spectral internals could take a look at this issue? This issue specifically mentions that "oneOf" could trip up the path mapping function, but we've found that this problem can also be triggered by simple nested schemas as well (i.e. a schema property is defined through a $ref, etc.). |
I've opened PR #2202 to fix this issue. With the changes in that PR, the output is now:
|
🎉 This issue has been resolved in version @stoplight/spectral-cli-v6.4.2 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
🎉 This issue has been resolved in version @stoplight/spectral-core-v1.12.4 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
Describe the bug
The spectral-core code related to mapping "resolved" paths to "unresolved" paths appears to get tripped up when dealing with schema references within a oneOf list. The testcase mentioned below contains a fairly simple OpenAPI document (api.yaml) along with a custom rule which verifies that each schema contains a valid description.
The custom rule's function logs the individual paths that are visited, along with the individual violations that
are found.
The API contains a handful of re-usable (named) schemas, with one (Soda) that lacks a description.
This Soda schema is referenced from within the Drink schema's oneOf list and is reachable in three
different ways:
To Reproduce
A testcase that demonstrates this problem can be found here:
https://github.com/padamstx/spectral-dedup-issue
The README.md contains detailed instructions to reproduce, but a summary is:
spectral lint api.yaml
Expected behavior
Based on the way in which the api.yaml file is defined, I'd expect a single error to be displayed
by spectral with the path
components.schemas.Soda
Screenshots
sample debug output from the custom function:
Environment:
This problem was found in spectral v6.2.1 running on Linux (Fedora 34)
Additional context
This problem was originally discovered during development of custom rules as part of the IBM openapi-validator project (https://github.com/IBM/openapi-validator), which is tightly integrated with spectral.
The text was updated successfully, but these errors were encountered: