fix(no-required-schema-properties-undefined): resolve false positives for bare-required schemas in allOf-composed types#2836
Open
jeremyfiel wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 929f198 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
8856aa1 to
929f198
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
no-required-schema-properties-undefinedrule incorrectly reported errors for two valid JSON Schema draft-04 patterns:Bare-required property sub-schema override — a property sub-schema that uses
requiredas a pure presence constraint with no localproperties, relying on the property's type definition resolved through a parentallOf.$ref:oneOf constraint fragments —
oneOfbranches that each contain only arequiredkeyword:Both are valid per the JSON Schema specification, where
requiredandpropertiesare fully independent keywords.Solution
Added a
hasPropertyInParentContexthelper to the rule'senterclosure. When the first two checks (localpropertiesandcompositionRoot) both fail to find a required property, the helper walks up theparentsstack to locate the ancestor schema that contains the current schema as a named property value. It then resolves that ancestor'sallOf/anyOf/oneOfsiblings and checks whether the property key is defined in any of them — the samehasPropertytraversal used elsewhere in the rule.This approach intentionally preserves misspelling detection: a misspelled key (e.g.,
giveNamevsgivenName) still fails the parent-context check and is reported as an error.Tests
Added 3 new test cases (23 total, all passing):
should not report bare required when property is defined in parent allOf siblingshould not report bare required in oneOf branches when property is defined in parent allOf siblingshould report misspelled required property even when parent allOf sibling defines the propertyrelates to #2320 #2060 #2061
Check yourself
Security
Note
Medium Risk
Adjusts linting logic for
requiredvalidation across composed schemas (allOf/oneOf/anyOf), which may change reported errors for some specs; test coverage reduces risk but behavior changes can impact user CI results.Overview
Fixes false positives in
no-required-schema-properties-undefinedby allowing barerequiredconstraints on property sub-schemas when the property’s type is defined in a parent composition sibling (includingoneOfbranches used as constraint fragments).Updates the reported error message text from “not defined” to “undefined”, adds regression tests for the new edge cases (and misspelling detection), and documents the supported JSON Schema patterns.
Reviewed by Cursor Bugbot for commit 929f198. Bugbot is set up for automated code reviews on this repo. Configure here.