Conversation
🦋 Changeset detectedLatest commit: 9548252 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 |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
|
| }); | ||
|
|
||
| it('should NOT report if one or more of the required properties are defined when used in schema with anyOf keyword', async () => { | ||
| it('should report when required properties are not declared in all anyOf branches', async () => { |
There was a problem hiding this comment.
This is the actual test case added.
| `); | ||
| }); | ||
|
|
||
| it('should not report required properties are present after resolving $refs when used in schema with allOf keyword', async () => { |
There was a problem hiding this comment.
Removed as duplicated.
| return {}; | ||
| } | ||
| visitedSchemas.add(schema); | ||
| const hasProperty = ( |
There was a problem hiding this comment.
Refactored similarly to the spec-discriminator-defaultMapping rule.
packages/core/src/rules/common/no-required-schema-properties-undefined.ts
Show resolved
Hide resolved
| return {}; | ||
| } | ||
| return elevateProperties(resolved.node, resolved.location?.source.absoluteRef); | ||
| if ( |
There was a problem hiding this comment.
Maybe we could make it more readable, like
const { schema, location } = resolved;
const hasDirectProperty =
schema.properties &&
getOwn(schema.properties, propertyName) !== undefined;
const checkSome = (schemas?: any[]) =>
schemas?.some((s) => hasProperty(s, propertyName, visited, location));
const checkEvery = (schemas?: any[]) =>
schemas?.every((s) => hasProperty(s, propertyName, visited, location));
if (
hasDirectProperty ||
checkSome(schema.allOf) ||
checkEvery(schema.anyOf) ||
checkEvery(schema.oneOf)
) {
return true;
}
There was a problem hiding this comment.
The point was to eagerly return once we've found the required property, but you're right--it might be not the most readable solution. I'll give it another try.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Shared visited set causes false positives across branches
- The bug was real and was fixed by cloning the visited set for each anyOf/oneOf branch so shared references no longer poison sibling branch checks.
Or push these changes by commenting:
@cursor push 94022a32f7
Preview (94022a32f7)
diff --git a/packages/core/src/rules/common/__tests__/no-required-schema-properties-undefined.test.ts b/packages/core/src/rules/common/__tests__/no-required-schema-properties-undefined.test.ts
--- a/packages/core/src/rules/common/__tests__/no-required-schema-properties-undefined.test.ts
+++ b/packages/core/src/rules/common/__tests__/no-required-schema-properties-undefined.test.ts
@@ -610,6 +610,51 @@
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
+ it('should NOT report when all anyOf branches share the same referenced property definition', async () => {
+ const document = parseYamlToDocument(
+ outdent`
+ openapi: 3.0.0
+ components:
+ schemas:
+ Base:
+ type: object
+ properties:
+ name:
+ type: string
+ BranchA:
+ allOf:
+ - $ref: '#/components/schemas/Base'
+ - type: object
+ properties:
+ huntingSkill:
+ type: string
+ BranchB:
+ allOf:
+ - $ref: '#/components/schemas/Base'
+ - type: object
+ properties:
+ curiosityLevel:
+ type: number
+ Cat:
+ type: object
+ anyOf:
+ - $ref: '#/components/schemas/BranchA'
+ - $ref: '#/components/schemas/BranchB'
+ required:
+ - name
+ `,
+ 'foobar.yaml'
+ );
+
+ const results = await lintDocument({
+ externalRefResolver: new BaseResolver(),
+ document,
+ config: await createConfig({ rules: { 'no-required-schema-properties-undefined': 'error' } }),
+ });
+
+ expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
+ });
+
it('should report when required properties are not declared in all anyOf branches', async () => {
const document = parseYamlToDocument(
outdent`
diff --git a/packages/core/src/rules/common/no-required-schema-properties-undefined.ts b/packages/core/src/rules/common/no-required-schema-properties-undefined.ts
--- a/packages/core/src/rules/common/no-required-schema-properties-undefined.ts
+++ b/packages/core/src/rules/common/no-required-schema-properties-undefined.ts
@@ -44,10 +44,12 @@
}
const check = (s: AnySchema) => hasProperty(s, propertyName, visited, resolved.location);
+ const checkEvery = (s: AnySchema) =>
+ hasProperty(s, propertyName, new Set(visited), resolved.location);
if (resolved.schema.allOf?.some(check)) return true;
- if (resolved.schema.anyOf?.every(check)) return true;
- if (resolved.schema.oneOf?.every(check)) return true;
+ if (resolved.schema.anyOf?.every(checkEvery)) return true;
+ if (resolved.schema.oneOf?.every(checkEvery)) return true;
return false;
};This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
packages/core/src/rules/common/no-required-schema-properties-undefined.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 70ce84a. Configure here.
packages/core/src/rules/common/no-required-schema-properties-undefined.ts
Show resolved
Hide resolved
…rties are not defined in all branches chore: refactor the no-required-schema-properties rule
70ce84a to
a52fa53
Compare


What/Why/How?
no-required-schema-properties-undefinedrule to report when a required property is not defined in everyoneOf/anyOfbranch.no-required-schema-propertiesrule code to avoid the 'grandparents' conceptDiscovered internally.
Check yourself
Security
Note
Medium Risk
Updates a core lint rule’s schema-walking logic, which may change reported violations (and potentially introduce false positives/negatives) across OpenAPI/AsyncAPI/Arazzo documents.
Overview
Fixes
no-required-schema-properties-undefinedso arequiredproperty must be present in everyanyOf/oneOfbranch (while still honoringallOfand$refchains), using a newhasPropertytraversal with cycle protection and a simplified composition-root lookup.Updates and expands the test suite to cover the new branch-aware behavior,
$ref/allOfnesting cases, and adjusts diagnostics (message text from "is undefined" to "is not defined") and expectations accordingly.Reviewed by Cursor Bugbot for commit 9548252. Bugbot is set up for automated code reviews on this repo. Configure here.