Skip to content

fix(rulesets): exclude non-schema enum properties from duplicated-entry-in-enum rule#2934

Merged
tomek-tursa-sb merged 4 commits into
stoplightio:developfrom
slegarraga:fix/issue-2199
May 20, 2026
Merged

fix(rulesets): exclude non-schema enum properties from duplicated-entry-in-enum rule#2934
tomek-tursa-sb merged 4 commits into
stoplightio:developfrom
slegarraga:fix/issue-2199

Conversation

@slegarraga

Copy link
Copy Markdown
Contributor

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 an enum field 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

  • Tests added / updated
  • Docs added / updated

Does this PR introduce a breaking change?

  • Yes
  • No

@slegarraga slegarraga requested a review from a team as a code owner April 6, 2026 16:56
…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
tomek-tursa-sb
tomek-tursa-sb previously approved these changes Apr 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes in this file are probably redundant

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slegarraga would you mind to have a look?

@slegarraga

Copy link
Copy Markdown
Contributor Author

Thanks for the ping, @tomek-tursa-sb. You were right — the generated Arazzo validators bundle change was redundant for this fix.

I restored packages/rulesets/src/arazzo/schemas/validators.ts to match develop, so the PR now only changes the OAS rule plus the regression tests. Commit: slegarraga@9b51f58

@tomek-tursa-sb

Copy link
Copy Markdown
Contributor

@slegarraga thank you for this contribution 💪

@tomek-tursa-sb tomek-tursa-sb merged commit a7822fa into stoplightio:develop May 20, 2026
8 checks passed
stoplight-bot pushed a commit that referenced this pull request May 21, 2026
## @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)
stoplight-bot pushed a commit that referenced this pull request May 21, 2026
## [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))
@stoplight-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 1.22.3 🎉

The release is available on @stoplight/spectral-rulesets-1.22.3

Your semantic-release bot 📦🚀

recommended: true,
message: '{{error}}',
given: ["$..[?(@property !== 'properties' && @ && @.enum)]"],
given: ["$..[?(@property !== 'properties' && @.enum && @.enum.constructor.name === 'Array')]"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the @ && null guard removed on purpose? I believe I'm seeing crashes when nimma hits a null node.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be:
$..[?(@property !== 'properties' && @ && @.enum && @.enum.constructor.name === 'Array')]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants