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

Do not validate description in parameters for links #515

Merged
merged 21 commits into from
Sep 6, 2019

Conversation

lag-of-death
Copy link
Contributor

@lag-of-death lag-of-death commented Aug 30, 2019

Fixes #272

Checklist

  • Tests added / updated
  • Docs added / updated

Does this PR introduce a breaking change?

  • Yes
  • No

@lag-of-death lag-of-death added t/bug Something isn't working WIP labels Aug 30, 2019
@lag-of-death lag-of-death self-assigned this Aug 30, 2019
"field": "@key",
"pattern": "^(?!.*(\\$ref))"
},
"given": "$..[?(@path === \"$['parameters']\" || (@.parameters && @parentProperty !== 'links'))]..[?(@.in)]",
Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor

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. :)

Copy link
Contributor

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

Copy link
Contributor Author

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

@lag-of-death lag-of-death force-pushed the fix/description-in-links-parameters branch from 92df9aa to 7422943 Compare September 4, 2019 12:24
@lag-of-death lag-of-death added this to the Aug '19 Hardening milestone Sep 4, 2019
@lag-of-death lag-of-death changed the title [WIP] Fix/description in links parameters Do not validate description in parameters for links Sep 4, 2019
@lag-of-death lag-of-death removed the WIP label Sep 5, 2019
@lag-of-death lag-of-death modified the milestones: Aug '19 Hardening, Sept '19 Sep 5, 2019
@@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"recommended": false,
"recommended": true,

"description": "Parameter objects should have a `description`.",
"recommended": false,
"type": "style",
"given": "$..[?(@parentProperty === 'parameters' && @.in)]",
Copy link
Contributor

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.

"description": "Parameter objects should have a `description`.",
"recommended": true,
"type": "style",
"given": "$..[?(@parentProperty !== 'links' && @.parameters)]['parameters']..[?(@.in)]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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====
Copy link
Contributor

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.

Copy link
Contributor

@chris-miaskowski chris-miaskowski left a 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)]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"given": "$..[?(@parentProperty === 'parameters' && @.in)]",
"given": "$.paths..[?(@parentProperty === 'parameters' && @.in)]",

Copy link
Contributor Author

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
severity: 1,
severity: DiagnosticSeverity.Warning,

"description": "Parameter objects should have a `description`.",
"recommended": true,
"type": "style",
"given": "$..[?(@parentProperty !== 'links' && @.parameters)]['parameters']..[?(@.in)]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"given": "$..[?(@parentProperty !== 'links' && @.parameters)]['parameters']..[?(@.in)]",
"given": "$.paths..[?(@parentProperty !== 'links' && @.parameters)]['parameters']..[?(@.in)]",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about $.components.parameters ?

Copy link
Contributor

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.

@lag-of-death
Copy link
Contributor Author

@P0lip, can you approve it?

@lag-of-death lag-of-death merged commit f035c05 into develop Sep 6, 2019
@lag-of-death lag-of-death deleted the fix/description-in-links-parameters branch September 6, 2019 08:35
@P0lip P0lip removed this from the Sept '19 milestone May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parameters in links objects shouldn't be linted for not having a description property.
4 participants