fix(rulesets): exclude non-schema enum properties from duplicated-entry-in-enum rule#2934
Conversation
…ry-in-enum rule The duplicated-entry-in-enum rule was incorrectly firing on properties named 'enum' in contexts like discriminator mappings and example values, where 'enum' is a data field rather than a JSON Schema keyword. Narrow the JSONPath filter to only match when the 'enum' value is actually an array, which is the only valid form for a schema enum keyword. Fixes stoplightio#2199
fc4f6c6 to
6472ad8
Compare
There was a problem hiding this comment.
changes in this file are probably redundant
|
Thanks for the ping, @tomek-tursa-sb. You were right — the generated Arazzo validators bundle change was redundant for this fix. I restored |
|
@slegarraga thank you for this contribution 💪 |
## @stoplight/spectral-rulesets [1.22.3](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-rulesets-1.22.2...@stoplight/spectral-rulesets-1.22.3) (2026-05-21) ### Bug Fixes * **rulesets:** exclude non-schema enum properties from duplicated-entry-in-enum rule ([#2934](#2934)) ([a7822fa](a7822fa)), closes [#2199](#2199)
## [1.12.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-ruleset-migrator-1.12.0...@stoplight/spectral-ruleset-migrator-1.12.1) (2026-05-21) ### Bug Fixes * **deps:** post lodash update changes for semantic release ([#2942](#2942)) ([bf530dd](bf530dd)) * **ruleset-migrator:** handle non function objects returned by requireResolve ([#2957](#2957)) ([60c6c56](60c6c56)) * **rulesets:** exclude non-schema enum properties from duplicated-entry-in-enum rule ([#2934](#2934)) ([a7822fa](a7822fa)), closes [#2199](#2199) * **rulesets:** fix handling relative references in externalValue ([#2944](#2944)) ([6666ccc](6666ccc)), closes [#2819](#2819) ### Features * **core:** add error line number for yaml and json ruleset validation ([#2945](#2945)) ([04c1db3](04c1db3))
|
🎉 This PR is included in version 1.22.3 🎉 The release is available on Your semantic-release bot 📦🚀 |
| recommended: true, | ||
| message: '{{error}}', | ||
| given: ["$..[?(@property !== 'properties' && @ && @.enum)]"], | ||
| given: ["$..[?(@property !== 'properties' && @.enum && @.enum.constructor.name === 'Array')]"], |
There was a problem hiding this comment.
Was the @ && null guard removed on purpose? I believe I'm seeing crashes when nimma hits a null node.
There was a problem hiding this comment.
Shouldn't this be:
$..[?(@property !== 'properties' && @ && @.enum && @.enum.constructor.name === 'Array')]
rulesets 1.22.3 (pulled in by the redocly/cli lockfile regen) crashes Spectral on r4 specs with null example values — upstream regression stoplightio/spectral#2934 dropped a null guard in duplicated-entry-in-enum. 1.22.2 is the last pre-regression release; drop the pin once a fixed release ships. Fixes #328
The duplicated-entry-in-enum rule was incorrectly triggering when enum is used as a property name in contexts like discriminator mappings or example values, rather than as a JSON Schema keyword. For example, a discriminator mapping like
mapping: { enum: ... }or example data with anenumfield would wrongly trigger the rule.The fix narrows the JSONPath filter to only match when the enum value is actually an array, since a JSON Schema enum keyword must have an array value. This avoids false positives while still correctly catching duplicate entries in actual schema enums.
Checklist
Does this PR introduce a breaking change?