Skip to content

fix(rulesets): relaxRequired does not traverse "not" schemas - #3083

Merged
Michał Rychel (micryc) merged 1 commit into
stoplightio:developfrom
cpruijsen:fix/issue-3068-c1c1bf93
Oct 13, 2026
Merged

Michał Rychel (micryc) merged 1 commit into
stoplightio:developfrom
cpruijsen:fix/issue-3068-c1c1bf93

Conversation

@cpruijsen

Copy link
Copy Markdown
Contributor

relaxRequired in packages/rulesets/src/oas/functions/oasExample.ts preserves required constraints throughout each not subtree.

The original code removes id from required inside not. The negated schema then accepts the valid request example, so oas3-valid-media-example rejects it.

Outside not subtrees, requests still relax readOnly requirements and responses still relax writeOnly requirements. The existing callback tracks not subtree pointers and uses parentKeyword to distinguish the keyword from a property named not.

Fixes #3068.

Checklist

  • Tests added / updated
  • Docs added / updated (not applicable to this behavior fix)

Does this PR introduce a breaking change?

  • Yes
  • No

Additional context

Tests cover the issue's referenced request schema, response writeOnly constraints, a property named not, and rejection when an example satisfies not.

Both new test files fail without this change and pass with it.

Required readOnly/writeOnly properties must not be removed from "not"
subschemas: a "not" schema is a negative constraint, so relaxing it
makes it match (and reject) documents that should be valid.

Fixes stoplightio#3068
@micryc
Michał Rychel (micryc) merged commit 95ab37e into stoplightio:develop Oct 13, 2026
10 checks passed
@micryc

Copy link
Copy Markdown
Contributor

Hi Christopher Pruijsen (@cpruijsen) Thank you for your contribution on fixing this issue, it should be included in next 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.23.1 🎉

The release is available on @stoplight/spectral-rulesets-1.23.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.

relaxRequired should not traverse across "not" relationships

4 participants