-
-
Notifications
You must be signed in to change notification settings - Fork 234
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
Do not validate description in parameters for links #515
Conversation
src/rulesets/oas/index.json
Outdated
"field": "@key", | ||
"pattern": "^(?!.*(\\$ref))" | ||
}, | ||
"given": "$..[?(@path === \"$['parameters']\" || (@.parameters && @parentProperty !== 'links'))]..[?(@.in)]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@P0lip, I'm kinda pulling my hair here. I can't find a rule that would satisfy OAS2 and OAS3. I was trying to create a rule that would eliminate parameters
under links
from the equation. I also wanted to make sure that even if we have:
links:
abc:
parameters:
param:
in: body
then we don't require .description
. I don't know, but I feel like we might need more rules or a custom function.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, Spectral would support an array of paths, so that you can supply a few json path expressions.
We could implement it as a part of 4.2 or 5.0.
For now, we could simply have 2 separate rules, one for oas2, and the other for oas3.
Once an array of paths can be provided, we can merge the rules.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can support "string or array" and keep it as non breaking. The next release is likely to be 5.0 but supporting both is just a good idea either way for the sake of existing users. No BC-breaks-for-the-sake-of-it here. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lag-of-death OAS2 doesn't have links :p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @P0lip, I'll try with more than one rule for this now. @philsturgeon, "OAS2 doesn't have links", that's correct. As I was saying in: https://github.com/stoplightio/spectral/pull/515/files/1a6bac8bc7ee4a3063b1e4d61f8c2b163993bb6a#r320012847 "I can't find a rule that would satisfy OAS2 and OAS3". So this was an attempt to have just one rule. Didn't work out
92df9aa
to
7422943
Compare
…ers' into fix/description-in-links-parameters
src/rulesets/oas3/index.json
Outdated
@@ -36,7 +36,7 @@ | |||
}, | |||
"oas3-operation-security-defined": { | |||
"description": "Operation `security` values must match a scheme defined in the `components.securitySchemes` object.", | |||
"recommended": true, | |||
"recommended": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"recommended": false, | |
"recommended": true, |
"description": "Parameter objects should have a `description`.", | ||
"recommended": false, | ||
"type": "style", | ||
"given": "$..[?(@parentProperty === 'parameters' && @.in)]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Over a call we tried to simplify it and use some sort of "union" but weren't able to find the right syntax.
src/rulesets/oas3/index.json
Outdated
"description": "Parameter objects should have a `description`.", | ||
"recommended": true, | ||
"type": "style", | ||
"given": "$..[?(@parentProperty !== 'links' && @.parameters)]['parameters']..[?(@.in)]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"given": "$..[?(@parentProperty !== 'links' && @.parameters)]['parameters']..[?(@.in)]", | |
"given": "$..[?(@parentProperty !== 'links' && @.parameters)]['parameters'].[?(@.in)]", |
Maybe check if single dot
is enough - I think it should be.
@@ -0,0 +1,34 @@ | |||
====test==== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a positive test checking whether we don't return warnings if descriptions are provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me this looks good, we had a video review. I left some minor comments. Pre-approving. Please address the remaining small feedback and feel free to merge.
"description": "Parameter objects should have a `description`.", | ||
"recommended": false, | ||
"type": "style", | ||
"given": "$..[?(@parentProperty === 'parameters' && @.in)]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"given": "$..[?(@parentProperty === 'parameters' && @.in)]", | |
"given": "$.paths..[?(@parentProperty === 'parameters' && @.in)]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@P0lip, what about $.parameters
?
code: 'oas3-parameter-description', | ||
message: 'Parameter objects should have a `description`.', | ||
path: ['components', 'parameters', 'address'], | ||
severity: 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
severity: 1, | |
severity: DiagnosticSeverity.Warning, |
src/rulesets/oas3/index.json
Outdated
"description": "Parameter objects should have a `description`.", | ||
"recommended": true, | ||
"type": "style", | ||
"given": "$..[?(@parentProperty !== 'links' && @.parameters)]['parameters']..[?(@.in)]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"given": "$..[?(@parentProperty !== 'links' && @.parameters)]['parameters']..[?(@.in)]", | |
"given": "$.paths..[?(@parentProperty !== 'links' && @.parameters)]['parameters']..[?(@.in)]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about $.components.parameters
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Urgh, forgot about that. Yeah, you are right, let's leave it as is.
@P0lip, can you approve it? |
Fixes #272
Checklist
Does this PR introduce a breaking change?