-
Notifications
You must be signed in to change notification settings - Fork 87
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
feat: check for missing required properties #314
Conversation
Check for missing required properties in a schema and any subschemas.
d844380
to
4ae5ddf
Compare
Codecov Report
@@ Coverage Diff @@
## main #314 +/- ##
==========================================
- Coverage 92.01% 91.90% -0.11%
==========================================
Files 73 73
Lines 2378 2348 -30
Branches 607 598 -9
==========================================
- Hits 2188 2158 -30
Misses 157 157
Partials 33 33
Continue to review full report at Codecov.
|
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.
Two quick questions/comments to look at before approving - code changes look good for the most part though!
given: | ||
- $.paths[*][*][parameters][*].schema | ||
- $.paths[*][*][parameters,responses][*].content[*].schema | ||
- $.paths[*][*][requestBody].content[*].schema |
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.
Is this operating on the resolved API definition? I see you're not checking inside of the components
section, is that because we would expect to see all schemas where they are actually used?
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.
Yes, that's correct!
src/.defaultsForValidator.js
Outdated
@@ -136,7 +135,8 @@ const defaults = { | |||
*/ | |||
const deprecated = { | |||
'no_produces_for_get': 'no_produces', | |||
'parameters.snake_case_only': 'param_name_case_convention' | |||
'parameters.snake_case_only': 'param_name_case_convention', | |||
'undefined_required_properties': 'missing-required-property', |
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.
I forget how this value gets used (I think in a warning message) but it may be good to call out the fact that it's a spectral rule
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.
Good point! The key is the old rule, and the value is the replacement rule if it exists.
I could do something simple like use missing-required-property (Spectral rule)
, which will result in, "Use missing-required-property (Spectral rule)
instead."
That might be confusing, though, so I could update the deprecation code to produce a different message when the new rule is a Spectral rule.
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.
I think that's fine, just something to indicate that the rule isn't going to be found in the validaterc file like the old one
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.
added the note in parentheses
cceddbd
to
48707aa
Compare
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.
Looks good! 👍
🎉 This PR is included in version 0.47.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Look for required properties that are not defined with the schema.
The
undefined_required_properties
rule only looked in thecomponents
section, which is why it is deprecated.The new rule enforces that required properties are defined in a given requestBody, response, and parameter schema and in any subschemas.
Related issue: #311