Skip to content

Comments

New Feature: バリデータにレスポンスの Content-Type を渡してコンテントネゴシエーションに対応する#23

Merged
wadakatu merged 4 commits intomainfrom
feat/content-negotiation-support
Feb 21, 2026
Merged

New Feature: バリデータにレスポンスの Content-Type を渡してコンテントネゴシエーションに対応する#23
wadakatu merged 4 commits intomainfrom
feat/content-negotiation-support

Conversation

@wadakatu
Copy link
Collaborator

概要

OpenApiResponseValidator::validate() にレスポンスの実際の Content-Type を渡せるようにし、同一ステータスコードに複数のコンテンツタイプが定義されている場合(コンテントネゴシエーション)の誤判定を解消する。

変更内容

  • OpenApiResponseValidator::validate() にオプションパラメータ ?string $responseContentType = null を追加(後方互換)
  • 非JSON Content-Type がスペックに定義されていれば success(スキップ)、未定義なら failure を返すロジックを追加
  • normalizeMediaType(), isContentTypeInSpec(), isJsonContentType() ヘルパーメソッドを追加
  • ValidatesOpenApiSchema trait の $hasNonJsonContentType ガード処理をバリデータ側に移動し、Content-Type をバリデータに渡すように変更
  • ユニットテスト7件、trait テスト2件(更新1件 + 新規1件)、統合テスト1件を追加

関連情報

Add optional $responseContentType parameter to OpenApiResponseValidator::validate().
When provided, non-JSON content types defined in the spec are skipped (success),
undefined types produce a failure, and JSON-compatible types proceed to schema validation.

Move the Content-Type mismatch logic from ValidatesOpenApiSchema trait into the
validator itself for a single source of truth.

Closes #22
Add 7 unit tests for OpenApiResponseValidator covering mixed content types,
charset handling, undefined types, and backward compatibility.
Update ValidatesOpenApiSchemaTest for new error message format.
Add integration test for content negotiation with coverage tracking.
Allow failure() to preserve matchedPath so coverage tracking works for
matched endpoints even on validation failures.

Add docblocks to isJsonContentType() and isContentTypeInSpec() with
preconditions. Clarify content negotiation comment to document the
intentional asymmetry between JSON and non-JSON type matching.

Narrow catch(Throwable) to catch(JsonException) in extractJsonBody()
to avoid masking unrelated errors.
Add tests for JSON Content-Type with charset parameter, vendor +json
suffix, and case-insensitive Content-Type matching through the
responseContentType parameter.

Add trait-level test for JSON response on mixed-content-type endpoint.
Strengthen assertion specificity in content type mismatch tests.
@wadakatu wadakatu merged commit f89ef5c into main Feb 21, 2026
8 checks passed
@wadakatu wadakatu deleted the feat/content-negotiation-support branch February 21, 2026 14:37
wadakatu added a commit that referenced this pull request Feb 21, 2026
…tation

Document the new content negotiation feature and responseContentType
parameter added in PR #23, including Features section, usage examples,
and API Reference updates.
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.

enhancement: バリデータにレスポンスの Content-Type を渡してコンテントネゴシエーションに対応する

1 participant