Skip to content

feat(oas): add object-with-properties-requires-type-object rule#2961

Open
slegarraga wants to merge 1 commit into
stoplightio:developfrom
slegarraga:feat/object-with-properties-requires-type-object
Open

feat(oas): add object-with-properties-requires-type-object rule#2961
slegarraga wants to merge 1 commit into
stoplightio:developfrom
slegarraga:feat/object-with-properties-requires-type-object

Conversation

@slegarraga
Copy link
Copy Markdown
Contributor

Summary

Implements the builtin rule proposed in #2203: schemas that define properties must also declare type: object.

  • Rule id: object-with-properties-requires-type-object
  • recommended: false (opinionated; opt-in like other style rules)
  • resolved: false (type belongs on the schema node, not on $ref targets)
  • Regression tests for OAS2 + OAS3

Why

Without type: object, JSON Schema validation does not restrict instances to objects — strings/booleans can pass unexpectedly when only properties is set.

Test plan

  • yarn jest packages/rulesets/src/oas/__tests__/object-with-properties-requires-type-object.test.ts

Closes #2203

Made with Cursor

@slegarraga
Copy link
Copy Markdown
Contributor Author

@maintainers Friendly nudge — rolling review welcome. Rule is opt-in (recommended: false) per #2203 discussion; happy to flip to recommended or adjust JSONPath if you prefer a stricter oas3.1 type: [object] case.

@slegarraga
Copy link
Copy Markdown
Contributor Author

Ready for review when you have bandwidth — mergeable, Wiz CI green, tests added. Closes #2203. Thanks.

@slegarraga
Copy link
Copy Markdown
Contributor Author

@tomek-tursa-sb Hi — you merged #2934 last week; this follow-up adds the opt-in rule from #2203 (tests + docs). Mergeable, Wiz green. A review when you have a cycle would be appreciated. Thanks.

@slegarraga
Copy link
Copy Markdown
Contributor Author

Local jest on rule tests: 5/5 pass. Branch is mergeable; let me know if you want this marked recommended: true before merge. Thanks.

@slegarraga
Copy link
Copy Markdown
Contributor Author

Related: #2962 (OAS 3.1 bearer scopes) — same ruleset area if useful to batch review.

@slegarraga
Copy link
Copy Markdown
Contributor Author

Ready for merge — closes #2203, MERGEABLE, CI summary ✅, local rule tests pass.

Opt-in rule (not recommended: true unless you want it default-on). Happy to flip that flag in a follow-up commit.

@slegarraga
Copy link
Copy Markdown
Contributor Author

@tomek-tursa-sb Batch review request when you have a cycle — three small Spectral PRs from the same contributor window:

PR What
#2963 Hotfix: null guard regression from #2934 → fixes #2959 crash (9 tests)
#2961 New opt-in rule object-with-properties-requires-type-object → closes #2203
#2962 OAS 3.1 bearer scopes on operations → closes #2643

All MERGEABLE, Wiz green. #2963 overlaps #2960 — land either for the null guard. Thanks again for merging #2934.

Adds an opt-in builtin rule for schemas that define properties without
declaring type: object, addressing a common OpenAPI footgun.

Closes stoplightio#2203
@slegarraga slegarraga force-pushed the feat/object-with-properties-requires-type-object branch from 0c521f2 to 08567e8 Compare May 22, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "Objects with properties must have type: object" rule to builtin spectral:oas ruleset

1 participant