Skip to content

fix(validation): guard spec traversal against malformed structural nodes (#259)#260

Merged
wadakatu merged 3 commits into
mainfrom
fix/spec-traversal-malformed-guard-issue-259
May 18, 2026
Merged

fix(validation): guard spec traversal against malformed structural nodes (#259)#260
wadakatu merged 3 commits into
mainfrom
fix/spec-traversal-malformed-guard-issue-259

Conversation

@wadakatu
Copy link
Copy Markdown
Collaborator

概要

malformed spec の構造ノード(非配列スカラー)が spec 走査経路で未捕捉 TypeError を出す問題を修正し、RequestBodyValidator と同じ粒度の loud な spec エラーとして surface するようにしました。

変更内容

OpenApiResponseValidator::validate() / OpenApiRequestValidator::validate() は spec を段階的に走査しますが、各段階で構造ノードが非配列スカラーのケースをガードしていませんでした。?? []キー不在には効くものの、スカラー値が存在する場合は素通しし、array_keys()array 型ヒント、SpecResponseKeyResolver::resolve() に到達して未捕捉 TypeErrorTypeError extends Error)でクラッシュしていました。#256(content/schema)・#258(responses[$status])が確立した per-response の malformed ガードを、その上位の走査経路にも広げます。

関連情報

wadakatu added 3 commits May 18, 2026 20:09
…es (#259)

A malformed spec whose `paths`, path item, operation, or `responses`
node decoded to a scalar slipped past the `?? []` absence guards and
raised an uncaught TypeError deep in the traversal path.

Add `is_array()` guards along the full traversal: four stages in
OpenApiResponseValidator (`paths`, path item, operation, `responses`
map) and three in OpenApiRequestValidator (`paths`, path item,
operation). Each surfaces a loud spec error ("expected object, got
scalar") instead of a misleading diagnostic or a crash. This extends
the per-response guards from #256/#258 across the entire traversal.

Add a malformed-paths fixture and extend the malformed fixture; cover
the new guards with TDD tests.
…#259)

Address multi-agent review feedback on PR #260.

Extend all four traversal-depth guards to also catch null structure
nodes. Switch presence checks for `paths` and operations from `isset`
to `array_key_exists`, since `isset` returns false for present-but-null
values and silently dropped them past the guard. Route path item and
responses lookups through `array_key_exists` / `?? null` so an explicit
null reaches the guard instead of being masked by `?? []`.

Replace the hardcoded "got scalar" error text with `get_debug_type()`
so null is no longer mislabeled as a scalar and the concrete type
(string, null, etc.) is reported.

Correct the guard comments to describe the actual behavior: each guard
prevents an uncaught TypeError on a non-array node.

Add fixtures covering each level: `/null-path-item`,
`/null-operation`, `/null-responses-map` and
`/scalar-operation-template/{id}` in malformed.json, plus a new
malformed-paths-null.json whose root `paths` is null.

Add tests for the null guards at every depth and verify that, for
templated paths, the message is keyed by the matched spec path.
…rds (#259)

Introduce a MalformedSpecNode helper (isMalformed() / describe()) and
route all 15 guard sites through it: #259 traversal (7), #258
responses[$status] (1), and #256 content/schema (7).

In addition to scalars and null, JSON lists ([...] written where an
object is expected) are now detected as malformed. List values
previously passed is_array() and were silently mis-resolved; they are
now surfaced as loud spec errors. Empty arrays remain tolerated since
{} and [] are indistinguishable.

Error messages now report the actual node type via describe()
(string / null / list, etc.) instead of the hardcoded "got scalar".

Add unit tests for the helper and list-value integration tests for
each guard family, and update existing assertions that assumed
"got scalar" to the real type. Extend malformed.json with list-value
paths and add the malformed-paths-list.json fixture.
@wadakatu wadakatu changed the title Bugfix: spec 走査経路の非配列ノードで未捕捉 TypeError になる問題を修正 (#259) fix(validation): guard spec traversal against malformed structural nodes (#259) May 18, 2026
@wadakatu wadakatu merged commit f25c0bb into main May 18, 2026
16 of 17 checks passed
@wadakatu wadakatu deleted the fix/spec-traversal-malformed-guard-issue-259 branch May 18, 2026 12:22
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.

tech-debt(validation) — OpenApiResponseValidator の spec traversal が非配列の構造ノードで未捕捉 TypeError になる

1 participant