Skip to content

fix(core): resolve a redefined rule's given against the aliases of its ruleset - #3089

Merged
Michał Rychel (micryc) merged 1 commit into
stoplightio:developfrom
M4Y4NK-V3RM4:fix/3085-override-given-aliases
Oct 30, 2026
Merged

Michał Rychel (micryc) merged 1 commit into
stoplightio:developfrom
M4Y4NK-V3RM4:fix/3085-override-given-aliases

Conversation

@M4Y4NK-V3RM4

Copy link
Copy Markdown
Contributor

Fixes #3085.

What was wrong

When a ruleset redefines a rule it inherits (for example a spectral:oas rule ID such as typed-enum), mergeRule() merges the new definition into the existing rule and keeps the base ruleset as its owner. Rule resolved given aliases through this.owner.aliases, so a given written in the extending ruleset was looked up in the base ruleset's aliases. An alias defined next to the override then failed with Alias "MyAlias" does not exist, as in the issue.

Change

  • Rule gets a separate alias source (aliasSource, defaulting to owner) that the given setter and getGivenForFormats() use, for both simple and format-scoped aliases.
  • mergeRule() sets it to the extending ruleset when an object override contains given, before Object.assign runs the given setter.
  • owner is unchanged, so formats, severity/enabled handling, documentationUrl and toJSON() behave as before.
  • An override that doesn't set given (e.g. 'warn' or true) keeps resolving the inherited given against the base ruleset's aliases, as today.
  • clone() is rebuilt from the original definition, so it keeps resolving against the owner, as before.

Checklist

  • Tests added / updated
  • Docs added / updated (no docs change needed)

Does this PR introduce a breaking change?

  • Yes
  • No

Additional context

Tests added:

  • ruleset.test.ts: a redefined rule whose given uses the extending ruleset's simple alias; the same with a scoped (targets/formats) alias, mirroring the issue; and inherited rules whose severity is the only change keep resolving against the base ruleset's aliases (simple and scoped).
  • linter.test.ts: the issue's scenario end to end through Spectral#run: it reports the result instead of throwing.

The new tests fail without the source change.

Run locally on top of develop (62527ee):

  • yarn jest packages/core/src/ruleset packages/core/src/__tests__/linter.test.ts: 206 passed
  • yarn jest packages/core and yarn jest packages/rulesets/src/oas: passed (run before one small follow-up edit to clone(); the narrower run above is after it)
  • yarn tsc --noEmit -p tsconfig.json: pass (after the workspace prebuild steps that generate version.ts and the validators)
  • eslint and prettier --check on the changed files: clean

Not run: the karma (browser) tests and the test-harness (CLI binary) suites.

Assisted-by: AI agent (Hark) with ZCode/GLM-5.3-Flash. The agent wrote the change, reviewed the diff and ran the checks above.

…s ruleset

When a ruleset redefines a rule from an extended ruleset (for example a
spectral:oas rule ID), mergeRule() keeps the base ruleset as the rule's
owner, and the given was resolved against the owner's aliases. An alias
defined next to the override therefore failed with
'Alias "X" does not exist'. Resolve given against the ruleset that
wrote it, and keep owner unchanged.

Fixes stoplightio#3085

Assisted-by: AI agent (Hark) with ZCode/GLM-5.3-Flash
@M4Y4NK-V3RM4
M4Y4NK-V3RM4 requested a review from a team as a code owner October 10, 2026 09:27
@micryc
Michał Rychel (micryc) merged commit 6497ddd into stoplightio:develop Oct 30, 2026
10 checks passed
@micryc

Copy link
Copy Markdown
Contributor

Hi M4Y4NK-V3RM4, thank you for your contribution! This fix will be included in the next Spectral release 🥳

Stoplighticus Roboticus (stoplight-bot) pushed a commit that referenced this pull request Nov 6, 2026
## [6.17.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-6.17.0...@stoplight/spectral-cli-6.17.1) (2026-11-06)

### Bug Fixes

* **cli:** lint files whose names contain glob characters ([#3101](#3101)) ([bf782be](bf782be)), closes [#2814](#2814)
* **cli:** switch binary target to node22 ([#3080](#3080)) ([1355fa6](1355fa6))
* **core:** resolve a redefined rule's given against the aliases of its ruleset ([#3089](#3089)) ([6497ddd](6497ddd)), closes [#3085](#3085)
* **functions:** clearer schema errors for array items and oneOf/anyOf ([#3095](#3095)) ([5c566df](5c566df)), closes [#1072](#1072)
* **functions:** republish 1.11.1 after failed release ([#3104](#3104)) ([d5da3c0](d5da3c0))
* **rulesets:** guard null definitions in oas2-discriminator given ([#3098](#3098)) ([74a5fe0](74a5fe0))
* **rulesets:** relaxRequired does not traverse "not" schemas ([#3083](#3083)) ([95ab37e](95ab37e)), closes [#3068](#3068)
Stoplighticus Roboticus (stoplight-bot) pushed a commit that referenced this pull request Nov 6, 2026
## [1.24.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-1.24.0...@stoplight/spectral-core-1.24.1) (2026-11-06)

### Bug Fixes

* **cli:** lint files whose names contain glob characters ([#3101](#3101)) ([bf782be](bf782be)), closes [#2814](#2814)
* **cli:** switch binary target to node22 ([#3080](#3080)) ([1355fa6](1355fa6))
* **core:** resolve a redefined rule's given against the aliases of its ruleset ([#3089](#3089)) ([6497ddd](6497ddd)), closes [#3085](#3085)
* **functions:** clearer schema errors for array items and oneOf/anyOf ([#3095](#3095)) ([5c566df](5c566df)), closes [#1072](#1072)
* **functions:** republish 1.11.1 after failed release ([#3104](#3104)) ([d5da3c0](d5da3c0))
* **rulesets:** guard null definitions in oas2-discriminator given ([#3098](#3098)) ([74a5fe0](74a5fe0))
* **rulesets:** relaxRequired does not traverse "not" schemas ([#3083](#3083)) ([95ab37e](95ab37e)), closes [#3068](#3068)
Stoplighticus Roboticus (stoplight-bot) pushed a commit that referenced this pull request Nov 6, 2026
## [1.23.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-rulesets-1.23.0...@stoplight/spectral-rulesets-1.23.1) (2026-11-06)

### Bug Fixes

* **cli:** lint files whose names contain glob characters ([#3101](#3101)) ([bf782be](bf782be)), closes [#2814](#2814)
* **cli:** switch binary target to node22 ([#3080](#3080)) ([1355fa6](1355fa6))
* **core:** resolve a redefined rule's given against the aliases of its ruleset ([#3089](#3089)) ([6497ddd](6497ddd)), closes [#3085](#3085)
* **functions:** clearer schema errors for array items and oneOf/anyOf ([#3095](#3095)) ([5c566df](5c566df)), closes [#1072](#1072)
* **functions:** republish 1.11.1 after failed release ([#3104](#3104)) ([d5da3c0](d5da3c0))
* **rulesets:** guard null definitions in oas2-discriminator given ([#3098](#3098)) ([74a5fe0](74a5fe0))
* **rulesets:** relaxRequired does not traverse "not" schemas ([#3083](#3083)) ([95ab37e](95ab37e)), closes [#3068](#3068)

### Features

* **repo:** minor release trigger ([#3079](#3079)) ([eabafec](eabafec))
@stoplight-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 1.24.1 🎉

The release is available on @stoplight/spectral-core-1.24.1

Your semantic-release bot 📦🚀

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.

Alias resolution fails ("Alias \"X\" does not exist") when a rule ID collides with a rule from an extended ruleset

5 participants