-
-
Notifications
You must be signed in to change notification settings - Fork 241
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(oas): add oas3-unused-component rule which detects all orphaned components #1440
feat(oas): add oas3-unused-component rule which detects all orphaned components #1440
Conversation
a728d67
to
1ea8aea
Compare
@P0lip I think this is now ready for review. I've rebased onto the current |
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 like it!
Let's just drop the other obsolete now rule and this should be good to go.
src/rulesets/oas/index.json
Outdated
@@ -643,7 +644,7 @@ | |||
}, | |||
"oas3-unused-components-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.
I'd say we can drop the rule at this point.
oas3-unused-component
somewhat overlaps with it.
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.
Dropping the rule entirely might cause unexpected results for users with a configuration that starts by disabling all rules and then selectively enables rules by name. Since Spectral does not issue a warning about rules it does not recognize in the configuration file, Spectral will silently stop linting their unused schemas.
But I'm happy to remove the rule if you think this is acceptable.
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.
Yeah, I'd say let's do it, but curious to hear what @philsturgeon thinks about the idea.
Since Spectral does not issue a warning about rules it does not recognize in the configuration file, Spectral will silently stop linting their unused schemas.
We're thinking to change it in the next major version. It's going to throw an error. Failing silently is usually not intended.
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.
The next version should be a major release so the impact should not be too unexpected, we'll just have to communicate it clearly.
837543d
to
394752f
Compare
Co-authored-by: Jakub Rożek <jakub@rozek.tech>
394752f
to
3e5f68a
Compare
I've updated the PR to remove the |
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.
Amazing work, thank you so much @mkistler!
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 a bunch! Great job.
Actually, your PR addressed #1073.
Co-authored-by: Jakub Rożek <jakub@rozek.tech>
This PR creates a new oas3 rule
oas3-unused-component
which detects and reports any unreferenced component (exceptsecuritySchemes
, which are not "referenced" in the normal way) in an OpenAPI document.Checklist
Does this PR introduce a breaking change?
Additional context
I'd like to replace the logic in our validator for finding and reporting unused components -- which is not configurable -- with a Spectral rule so that users can override the severity for their out purposes. We've gotten requests from users for this capability:
IBM/openapi-validator#172
But I can't use
oas3-unused-components-schema
because this would be a regression -- our logic detects all of types of unused components: schemas, parameters, responses, requestBodies, headers, examples, links, and callbacks.So this PR creates a new rule that is a superset of
oas3-unused-components-schema
that detects all unused components (except securitySchemes). It leverages the underlyingunreferecedReusableObject
function internally, so the logic is (IMHO) very straightforward.Because this new rule is a superset of
oas3-unused-components-schema
, I changed that rule to be "recommended: false" and set the new rule to "recommended: true"