-
-
Notifications
You must be signed in to change notification settings - Fork 248
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 {{path}} as option for messages in rulesets #572
Comments
@kylesykes
By default all Spectral rules are executed against resolved document, however you can change it. security-zero-or-one-oauth-scope:
description: Every OAuth2 secured endpoint defines scopes
given: $..paths.*[?( @property != 'parameters' )].security[0]
severity: error
resolved: false # this is true by default
message: 'Errored at {{property}}... Error message is: {{error}}'
then:
field: oauth2
function: length
functionOptions:
min: 1 |
The JSON Path should be in the result but maybe having it in stylish is too unstylish. Can we have a more verbose output format which makes this easier to understand? The JUnit output (#478) we just added can do this right? Maybe this JUnit feature would actually take care of this PR instead of adding the path to other outputs? We also have a HTML output (#389) which would be another verbose format to help solve this issue. If either of these solutions help lets close this one down. |
Actually, if the JUnit output would contain the more detailed (necessary in our case) path information (more than what the CLI currently supports), that would actually be a far better solution since it would better integrate into Gitlab's CI. I'd be happy to close this down as soon as I can validate that something like the path could be included, otherwise I can easily shift this from "add it to the CLI" to "add the path information to the Junit output" if it's not there currently (because I see a lot of value in that, especially for people who have a large number of unresolved files that others are editing). I saw the Junit PR was merged into develop a few days ago, so I tried using it with the Thank you for your time and effort. We've been blown away by the quality of your tools compared to others and the progress you all make on them and we will absolutely be putting Spectral through it's paces for this project. |
If storing that information in JUnit is enough, I'm all in for doing it so.
@kylesykes We haven't released it yet. :) 4.2.0 release containing JUnit formatter should be out soon, though! |
Added in JUnit! #588 Play around with develop once it's merged and let us know if there is any trouble. :) |
That's interesting. Do your custom functions provide any Regarding the second request, I'll verify it and get back to you. |
Actually, I think I goofed on my initial guess at the issue. That particular rule doesn't use a custom function (I have another almost identically named that does however). I have no idea what's happening now, or what's special about this rule versus others that are working fine so here's some examples. Here's a rule with almost the same JSONPath syntax that is appropriately put into the right
And here's the one that's throwing things in the
Things I can spot that are different is the bottom one traverses a path that gets resolved internally (.responses['200'] in the spec is just a If it's at all helpful, here's a barebones skeleton of what I'm working with (the actual spec is huge and way more complicated):
Fun fact, did you know JSONPath-Plus doesn't support |
@kylesykes EDIT: |
For those who are curious, it works perfectly. We use Gitlab and Spectral runs during PRs, and now (after #607 was done) the JUnit output is able to be parsed perfectly by Gitlab, pointing exactly to where the problem is (in the larger unresolved spec, which line numbers alone didn't accommodate): Thank you all very much! |
@kylesykes great to hear that! Thanks again for all the awesome feedback you provided. ❤️ |
User story.
As a writer of rulesets against a large OA3 spec which is split into many different files that get resolved prior to running Spectral, I want to be able to have the
message
in the ruleset be able to reference the current{{path}}
that the error was triggered from to help guide where the issues were in the non-resolved files (where line numbers are useless).Is your feature request related to a problem?
We use Spectral as a CLI tool in a CI pipeline, and triggers on PR changes to a very hefty spec which gets first resolved, then linting the resolved spec. Currently we have over 300+ routes, and if someone makes a change to a large majority of routes (for example, adding oauth scopes to security), we can write a rule to validate that we actually added something to them all with the following ruleset:
However if the validation fails, we might only see the line number and the property name (in our case,
oauth2
), of which there might be hundreds to manually sift through in the non-resolved files to find the issue because the line number is meaningless when trying to look at the non-resolved OA3 files(see screenshot below).Describe the solution you'd like
If it's easy to add in given the context, it would be awesome if we could give the option to dump out the current path which caused the error.
So a message of:
message: 'Errored at {{path}}... Error message is: {{error}}'
could give a message of:
Errored at paths["/v1/errorCodes"].get.security[0].oauth2 ... Error message is: min length is 1
We did experiment with running Spectral against the unresolved OA3 files, but it wasn't successful with detecting things correctly. I'm not sure what sort of resolving is going on under the hood, but if the solution is us doing something incorrectly with regards to using Spectral against the unresolved spec, that would also be a great solution (since it should identify the offending file, where the line number may be useful depending on how things were resolved).
We are open to any suggestions to help devs easily identify where they've broken a rule! Thanks!
Additional context

Sample error currently:
Experimenting with using Spectral on an unresolved file produces a bunch of errors which fail to identify path params in this particular file:

The text was updated successfully, but these errors were encountered: