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: 2cc6d1f 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
929f198 to
2cc6d1f
Compare
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 4 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 not report bare required in anyOf 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
Low Risk
Lint-rule behavior change with broad test coverage; reduces false positives without relaxing checks for genuinely undefined or misspelled required keys.
Overview
Fixes false positives in
no-required-schema-properties-undefinedfor valid JSON Schema patterns where a property sub-schema only addsrequired(oroneOf/anyOfbranches with barerequired) while the field’s shape comes from a siblingallOf$ref.The rule now uses
hasPropertyInParentContextto walk ancestors, match the property key, and resolveallOf/anyOf/oneOfsiblings before flagging a name as undefined; diagnostics use “is undefined” instead of “is not defined.” New tests cover barerequired,oneOf/anyOfconstraint fragments, and misspellings still reported; v1/v2 docs and a patch changeset document the behavior.Reviewed by Cursor Bugbot for commit 2cc6d1f. Bugbot is set up for automated code reviews on this repo. Configure here.