-
Notifications
You must be signed in to change notification settings - Fork 15
CLOUDP-306578: IPA-123: Enums #650
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
Conversation
| - Skips validation if the schema has an exception defined for this rule | ||
| message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-123-enum-values-must-be-upper-snake-case' | ||
| severity: error | ||
| resolved: 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.
FYI: drive-by fix, not to duplicate the check for referenced schemas. The rule validates only the root component
| import { resolveObject } from './utils/componentUtils.js'; | ||
|
|
||
| const RULE_NAME = 'xgen-IPA-123-enum-values-should-not-exceed-20'; | ||
| const ERROR_MESSAGE = 'Enum arrays should not exceed 20 values. Current count: '; |
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.
| const ERROR_MESSAGE = 'Enum arrays should not exceed 20 values. Current count: '; | |
| const ERROR_MESSAGE = 'Enum arrays should not exceed 20 values, consider opting for a string instead. Current count: '; |
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 also thought about including it, but not sure if producers would understand the difference, because type is already string. What do you think?
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 took it right from the IPAs, so if it's unclear we should probably update the IPA too to explain. No string opinion though, I think in the context it makes sense
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.
Until the investigation for the reusable enum schemas are finalized, I think we should not give any suggestions here. I will note that the relevant IPA and error message here should be refined according to the investigation results
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.
IMHO it is premature to put recomendation for using string. We moving problem to area we also want to fix (long strings).
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.
Ticket created: https://jira.mongodb.org/browse/CLOUDP-310775
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 be clear - I agree that each IPA should have a clear message how to workaround the problem.
For this IPA we agreed that we're going to delegate it outside this PR as more investigation is required.
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.
Pull Request Overview
This pull request implements a new validation rule ensuring that enum arrays in the OpenAPI schema do not exceed 20 values. The key changes include:
- Adding a new rule function (IPA123EnumValuesShouldNotExceed20.js) that checks the enum value count.
- Updating documentation (README.md) to include the new rule.
- Modifying the Spectral ruleset configuration (IPA-123.yaml) to register the new rule.
- Providing comprehensive tests for the new rule in IPA123EnumValuesShouldNotExceed20.test.js.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tools/spectral/ipa/rulesets/functions/IPA123EnumValuesShouldNotExceed20.js | New function to enforce the maximum allowed enum values |
| tools/spectral/ipa/rulesets/README.md | Documentation update for the new rule |
| tools/spectral/ipa/rulesets/IPA-123.yaml | Rule configuration update to include the new rule |
| tools/spectral/ipa/tests/IPA123EnumValuesShouldNotExceed20.test.js | Added tests covering various scenarios for the new rule |
| errors: [], | ||
| }, | ||
| { | ||
| name: 'valid on with reusable schemas', |
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.
FYI: Reusable enum schemas are ignored now
| message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-123-allowable-enum-values-should-not-exceed-20' | ||
| severity: warn | ||
| resolved: false | ||
| given: '$..enum' |
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.
❤️
tools/spectral/ipa/rulesets/functions/IPA123EnumValuesShouldNotExceed20.js
Outdated
Show resolved
Hide resolved
wtrocki
left a comment
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.
LGTM althought strong recomendation to keep enum size as parameter for rule inputs
wtrocki
left a comment
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.
LGTM!
|
In driveby next time cover parameter in rule description |
Proposed changes
Jira ticket: CLOUDP-306578
Found 61 violations to fix
Checklist
Changes to Spectral
Further comments