question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New dedupe in 5.0.0 prevents multiple rule violations to be reported from the same source range

See original GitHub issue

Describe 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

  1. Given an OpenAPI file with multiple paths
  2. Write a custom rule which targets $.paths
  3. Attach the rule to a custom function which iterates over paths and returns an array of rule violations
  4. 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
disposedtrolleycommented, Mar 27, 2020

@nulltoken looks great! Thanks for keeping the docs fresh 😄

1reaction
nulltokencommented, Mar 25, 2020

Have the docs been updated to reflect these changes? Maybe a warning that targeting a broad block of the OAS isn’t such a good idea anymore? Otherwise happy to get this one closed out!

@disposedtrolley I’ve just opened #1035 to try and document this. Feedback woud be welcome 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Only first message displayed for custom function handling ...
I remember reading about it in New dedupe in 5.0.0 prevents multiple rule violations to be reported from the same source range #920...
Read more >
dedup - Splunk Documentation
Description: The dedup command retains multiple events for each combination when you specify N . The number for N must be greater than...
Read more >
Understanding the Dedup and FRBR Processes (Primo VE)
The duplication detection or matching process is based on creating a dedup vector for every Alma record (and all imported records from external...
Read more >
How to Remove Duplicates in Google Sheets in 2023
Use the Google Sheets QUERY function to remove duplicates in a spreadsheet on multiple columns. Identify and remove duplicates from Google ...
Read more >
Finding and fixing duplicates in webpack with Inspectpack
Old webpack's DedupePlugin doesn't have anything to do this time, as there are no identical duplicate code sources. Assessment: Our bundle has ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found