Skip to content
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

Add option to support override-ready paths in Spectral diagnotsics #2770

Open
DavidBiesack opened this issue Jan 10, 2025 · 2 comments
Open

Comments

@DavidBiesack
Copy link

User story.

As a Spectral user, I can use a command line option so that the locations in Spectral's error/warning/information diagnostics use the same notation/syntax as the overrides/files notation in a Spectral ruleset.

Is your feature request related to a problem?

It is tedious and error prone to manually specify the files locations in ruleset overrides.
The diagnostics emitted by Spectral use one format that differs from that used in a ruleset.

I.e. for the Redocly Museum sample OpenAPI
and the oas and Spectral OWASP ruleset, Spectral emits many diagnostics, such as

 108:17  warning  owasp:api4:2023-rate-limit-responses-429    Operation is missing rate limiting response in responses[429].                                      paths./special-events/{eventId}.get.responses

If one wanted to add an override for a specific instance (not just disable the entire rule), one must "map" the path notation paths./special-events/{eventId}.get.responses to

overrides:
  files:
    - 'test/data/openapi.yaml#/paths/~1special-events~1%7BeventId%7D/get/responses'

Describe the solution you'd like

Add a command line option so that the Spectral output uses the notation required for the ruleset overrides
Such as

 108:17  warning  owasp:api4:2023-rate-limit-responses-429    Operation is missing rate limiting response in responses[429]. test/data/openapi.yaml#/paths/~1special-events~1%7BeventId%7D/get/responses

Additional context

Note that the new location should use the relative file location, not the absolute file location that Spectral emits when processing a file, since ruleset files normally use relative files file paths (i.e. relative to the current directory when running the spectral CLI)

@DavidBiesack
Copy link
Author

DavidBiesack commented Jan 10, 2025

Another option is to add a json-pointer or similar property to each item in the output when using --format json.
I don't know which other output formats are extensible - I don't what most of the output formats

["json", "stylish", "junit", "html", "text", "teamcity", "pretty", "github-actions", "sarif", "markdown","gitlab"]

mean, so only adding to JSON will meet the need without getting too complex.

@DavidBiesack
Copy link
Author

I tried to work on a PR to address this in packages/formatters/src/json.ts but when I clone the repo, yarn && yarn build yielded errors and the CONTRIBUTING guide does not make it clear how to add a dependency (the formatters uses package.json -- so how/where do I add a dependency to the json-pointer package?

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

No branches or pull requests

1 participant