-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Rule: remove when #585
Comments
@philsturgeon @marbemac do you have anything against? |
Sure! |
Hello, I would like to get your opinion/inputs on a rule I want to create (and on which I thought the When I've a request with a path parameter such as those in the attach file, then I would like to have an error that tells me that I've forget the 404 response for the requests:
For the moment, I don't know how this can be performed and I imagine that the |
I've continued my research on this point and I think that I can find a work around using JSONPath expression. Only thing is... I don't think the tool you're using to parse a JSON can do what I have in mind. Before going to the point, I'd like to share with you the behavior I'm working in case this could also help in the building of the Spectral project. Ensure that the path parameters follow a patternThe first rule I've created was to ensure that all the path parameters do follow a specific naming convention (often used with resource_id). This latter was written this way:
404 response for requests with path parametersThen I try to define a second rule that assess if a request with a path parameter do have a 404 response. For this latter, I'd to use the pattern that I've defined in the previous steps and I found that it could be done with a rule such as:
The only thing is... the operator @philsturgeon @P0lip I don't know what are the impacts of this change in your code but I do you think that it would be a good idea to give this opportunity to your community. Do you share this point of view? :) |
Finally got something working with a this rule: missing-404-response:
type: validation
severity: error
recommended: true
description: Any operation must define the 404 response.
message: "The request must define a 404 response."
given: "$.paths[?(@property.includes('_id}'))][?(@property === 'get' || @property === 'post' || @property === 'delete' || @property === 'options' || @property === 'patch' )].responses"
then:
field: '404'
function: truthy I didn't know that we could directly use javascript functions in a JsonPath and I think that it could be great that you set in your documentation that such function can directly be use :) |
@Amachua,
Yeah, you can use filter expressions, which are evaluated during the runtime.
Mind opening a PR and sharing what you achieved in the docs? :) |
@P0lip what is the plan here? |
Chore summary
Remove
when
member fromIRule
interface.It's used only by
parameter-description
rule and does not really seem to be needed, as a jsonpath expression could be used instead.Moreover, we don't really have that property documented anywhere, therefore the impact is likely to be low.
The text was updated successfully, but these errors were encountered: