fix(rulesets): duplicated-entry-in-enum - support null values#2960
fix(rulesets): duplicated-entry-in-enum - support null values#2960DougEdey-Slice wants to merge 1 commit into
Conversation
…s when checking for duplicates
|
Nice follow-up to the enum edge cases — null in enum arrays is easy to miss. From #2934 land: worth confirming |
slegarraga
left a comment
There was a problem hiding this comment.
LGTM — null enum handling matches OAS 3.0 nullable enums and 3.1 semantics from #2959.
- Test matrix covers null in
enumarrays without false positives on valid enums. validators.tstweak is minimal and scoped to the duplicated-entry rule path.
No concerns from my side; thanks for the fix.
slegarraga
left a comment
There was a problem hiding this comment.
LGTM — null enum handling matches #2959; tests cover nullable enums without false positives. Thanks for the fix.
|
@DougEdey-Slice Thanks — this addresses the regression from #2934 (my merge). Suggest adding a test case for issue #2959 reproducer ( |
|
@tomek-tursa-sb Maintainer review when possible — 2 contributor approvals, fixes #2959 (production crash). Alternative: #2963 has the same guard + explicit reproducer test from the issue. Either PR unblocks users on spectral-cli 6.16.x. |
## Summary - Pin `@stoplight/spectral-rulesets` to `1.22.2` in the `lint-openapi` target. - `1.22.3` introduced a regression in the `duplicated-entry-in-enum` rule that crashes Spectral with `Cannot read properties of null (reading 'enum')`. See [stoplightio/spectral#2959](stoplightio/spectral#2959). - Fix is in flight upstream ([#2960](stoplightio/spectral#2960) / [#2963](stoplightio/spectral#2963)) --------- Co-authored-by: Patrik Ragnarsson <patrik@starkast.net>
slegarraga
left a comment
There was a problem hiding this comment.
Reviewed this against #2959 and my own #2963, since they overlap.
The 3.1 coverage here is the right call: null is a valid enum member in OAS 3.1 (enum: [1, 2, 3, null]), and flagging duplicated nulls ([null, …, null] → items #0 and #6) is a real gap the original rule missed. Nice.
One coordination note: this and #2963 fix different facets of #2959 and will conflict on oas/index.ts and duplicated-entry-in-enum.test.ts. #2963 adds @ != null to the rule's given selector to stop a TypeError when the selector hits a null node (e.g. foo: null inside an example value, where reading @.enum throws). That null-node crash isn't exercised by the cases here (these are all schema enums), so I think both changes are needed: the selector guard to avoid the crash, plus your 3.1 null-entry semantics. Happy to rebase #2963 on top of this so it's a single clean change if that's easier to merge.
Fixes #2959.
This handles
nullenum values, which is supported/required by OAS3.1 for nullable enumsThis updates the tests & the ruleset to support nulls, which OAS3.0 does support: https://swagger.io/docs/specification/v3_0/data-models/enums/#nullable-enums
First time contributor so let me know if I need anything else :)
Checklist
Does this PR introduce a breaking change?