-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
Can't show more than one message from a custom function, even though the response is an array #1030
Comments
Hey! Thanks for this bug report. This reminds me a lot of a discussion that happened in #920. Could you see if the explanation in #920 (comment) and the proposed resolution solves the issue you're facing? |
Hi @nulltoken many thanks for the response. I have taken a look at #920 . I am fairly new to spectral so I find it a little hard to decide if the fix proposed to #920 will work for me. Perhaps it would help if I explain my use-case. We already have a fairly comprehensive set of syntactic rules, and I am working on some custom functions that help to enforce some more 'structural/semantic consistency' rules. This means that, for example, the 'name' of a rest resource is used consistently across;
This means that;
|
@nulltoken OK, I have done a little more reading, and I think that this comment from #920 is the key proposal:
I think this refers to setting the return [
{
message: 'Message 1',
path: [ ...x... ]
},
{
message: 'Message 2',
path: [ ...y... ]
},
] Is that correct? Could you give an example? I also believe it to be the case that another way for me to work around this would be to use a custom deduplication strategy: https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/guides/javascript.md#using-custom-de-duplication-strategy |
@RobPhippen You're spot on! The typedEnum.ts function might be a good piece of code to glance at. I've also just opened #1035 to try and document that.
I wouldn't advise you to tweak this function to solve this kind of issue. Returning a different path per result is the way to go. |
Hi @nulltoken and thanks for taking the time to look at this - I really appreciate it. Having read the example from However, the consistency rules I mentioned above really do legitimately result in more than one violation relating to a particular path. I attempted to cope with this by constructing further 'virtual/logical' path elements. Probably with very good reason, spectral currently rejects those (I assume, because they are 'paths that do not exist in the current document') Do you have any thoughts on what I could do? In the worst case I will split them in to separate rules. Reading the new doc, I wonder if it would be possible to allow a function to optionally return a |
My experience around that would favor this approach. It's usually easier to deal with simple rules that do one thing rather than a big one that performs lots of checks. Simple rules are usually easier to manage, describe and document. Also, it happens that for specific use cases you'd like to ignore a specific finding (#939) and dealing with atomic rules makes that also easier. |
Describe the bug
Custom functions can return an array of objects, but only the first element can be displayed.
To Reproduce
functions/fail_func.js
.spectral.yml
spectral lint myopenapi.yaml
Get message
Expected behavior
at step 3, I expect to see both 'Message 1' and 'Message 2'
Comment
If that is not the expected behaviour, then perhaps the response from a custom function should not be an array?
The text was updated successfully, but these errors were encountered: