New dedupe in 5.0.0 prevents multiple rule violations to be reported from the same source range
See original GitHub issueDescribe the bug We’ve recently upgraded to Spectral 5.0.0 and have noticed that multiple rule violations for the same range in the code are no longer reported. We have some rules which target a broad block of the OpenAPI JSON (i.e. a map of objects), and we delegate our custom rule function to iterate over the map and return an array of rule violations. All of these violations would point to the same source file, column, and line number.
Looking through the PR history, I see that a fingerprinting function has been added which attempts to eliminate duplicate rule violations being reported. The function only seems to use the code
, path
, range
, and source
attributes of the rule to compute a fingerprint, not the error message itself. This means that if we return an array of rule violations from custom functions, only the first element will be rendered to the user.
To Reproduce
- Given an OpenAPI file with multiple paths
- Write a custom rule which targets
$.paths
- Attach the rule to a custom function which iterates over
paths
and returns an array of rule violations - Observe that only the first rule violation in the returned array is reported to the user
Expected behavior All rule violations should be reported.
Environment (remove any that are not applicable):
- Library version: 5.0.0
- OS: macOS 10.15.2
Additional context I know that targeting a broad block of JSON for rules isn’t optimal, but there may be some cases where we need more complex logic than what the JSONPath syntax can offer to run our rules. I think it might be beneficial to:
- modify the dedupe function to account for the error message when computing the fingerprint.
- update the custom rules section of the docs to strongly recommend providing JSONPath expressions which target individual fields only
P.S. thanks for all the hard work that went into 5.0.0! We’re seeing much better performance now.
/cc @nogates @davidlopezre @magnetikonline @adoragoh just something to watch out for when writing Spectral rules 😃
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
@nulltoken looks great! Thanks for keeping the docs fresh 😄
@disposedtrolley I’ve just opened #1035 to try and document this. Feedback woud be welcome 😄