Repository navigation
feat(rulesets): add object-with-properties-requires-type-object rule - #2961
Open
Sebastian Legarraga (slegarraga) wants to merge 1 commit into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 of 2 tasks
Sebastian Legarraga (slegarraga)
force-pushed
the
feat/object-with-properties-requires-type-object
branch
from
May 22, 2026 14:09
0c521f2 to
08567e8
Compare
Adds an opt-in rule for schemas that define properties without declaring type: object. Without the type, JSON Schema does not restrict instances to objects, so strings and other primitives pass validation. In OAS 3.1 a type array that includes object, such as [object, 'null'], also passes. The check uses if/then/else instead of anyOf so a bad type is reported once rather than once per branch. Closes stoplightio#2203
Sebastian Legarraga (slegarraga)
force-pushed
the
feat/object-with-properties-requires-type-object
branch
from
October 22, 2026 15:56
21f68f5 to
f0b8759
Compare
This branch has not been deployed
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.
Summary
Implements the rule proposed in #2203: a schema that defines
propertiesmust also declaretype: object.object-with-properties-requires-type-objectrecommended: false. It's opinionated, so it's opt-in like the other style rules.resolved: false, because the type belongs on the schema node, not on$reftargets.typearray that includesobject(for example[object, "null"]) passes.if/then/elseinstead ofanyOf, so a badtypeis reported once instead of once per branch.docs/reference/openapi-rules.md.Why
Without
type: object, JSON Schema validation doesn't restrict instances to objects, so strings and booleans pass when onlypropertiesis set.Tests
7 cases covering OAS 2, OAS 3.0 and OAS 3.1, including type arrays with and without
object.yarn jest packages: 2029 passed, 1 skippedenum: ['object'], or dropping thethen, theelseorrequired, each makes at least one case fail.Closes #2203