Repository navigation
fix: report properties and items on any mismatched type in no-schema-type-mismatch - #3222
dimitropoulos wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: c4ef559 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 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 |
There was a problem hiding this comment.
🟡 Changes recommended
Boolean items schemas remain undetected, and the documentation overstates union-type coverage.
2 open findings
What changed in this PR
Expands no-schema-type-mismatch to detect structural keywords on primitive schema types.
Changes:
- Broadens mismatch detection and error messages.
- Adds focused tests and documentation.
- Adds release notes for stricter lint behavior.
| File | Description |
|---|---|
packages/core/src/rules/common/no-schema-type-mismatch.ts |
Broadens mismatch checks. |
packages/core/src/rules/common/__tests__/no-schema-type-mismatch.test.ts |
Tests primitive-type mismatches. |
docs/@v2/rules/common/no-schema-type-mismatch.md |
Documents expanded behavior. |
.changeset/quiet-schemas-match.md |
Records the behavioral change. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return; | ||
| } | ||
|
|
||
| if (schema.type !== 'array' && schema.items) { |
There was a problem hiding this comment.
Leaving this as is. items: false on a non-array schema has no effect, so it can't cause the kind of tooling breakage this rule is meant to catch, and flagging it would just be noise. The truthiness check is also what the rule already did for object + items before this PR, so keeping it leaves existing behavior alone.
| - Only a schema of type `array` may include an `items` field. | ||
| - Only a schema of type `object` may include a `properties` field. |
There was a problem hiding this comment.
Fixed in c4ef559. The docs now say the rule only checks single-value type, and a new test asserts that type: [object, 'null'] with properties reports nothing.
Performance Benchmark (Lower is Faster)
|


What/Why/How?
no-schema-type-mismatchonly reported two specific combinations:propertiesontype: arrayanditemsontype: object. Any other mismatch passed, including this one:This made it into our API description and broke code generation for us. Nothing in
recommended,recommended-strict, orallflagged it, even though this rule exists to catch exactly this kind of mistake.The rule now reports:
propertieson any type other thanobjectitemson any type other thanarrayThe existing messages for
arrayandobjectdon't change. The rule still only checks schemas wheretypeis a single string, so a 3.1 list such astype: [string, 'null']is skipped, same as before.Because the rule is
errorinrecommended, descriptions that passed before can now fail. The changeset includes a note about this.Reference
Testing
type: stringwithpropertiesandtype: integerwithitems. The existing tests pass unchanged.--extends recommendedagainst the snippet above. It now reportsSchema type mismatch: 'string' type should not contain 'properties' field.Screenshots (optional)
Check yourself
Security
Note
Medium Risk
Stricter default lint in
recommendedcan surface new errors on existing OpenAPI descriptions; rule logic change is localized to schema validation.Overview
Tightens
no-schema-type-mismatchso invalid structural keywords are caught for all single-stringtypevalues, not onlyobject/arraycross-mismatches.The rule now errors when
itemsappears on any type other thanarrayand whenpropertiesappears on any type other thanobject(e.g.type: stringwithproperties). It skips schemas whosetypeis not a single string (such astype: [object, 'null']). Diagnostic messages include the actual declared type.Docs and tests cover primitives and multi-type schemas. The changeset flags that APIs using
recommendedmay newly fail lint where mismatches were previously ignored.Reviewed by Cursor Bugbot for commit c4ef559. Bugbot is set up for automated code reviews on this repo. Configure here.