New Feature: バリデータにレスポンスの Content-Type を渡してコンテントネゴシエーションに対応する#23
Merged
New Feature: バリデータにレスポンスの Content-Type を渡してコンテントネゴシエーションに対応する#23
Conversation
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
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.
1 task
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.
概要
OpenApiResponseValidator::validate()にレスポンスの実際の Content-Type を渡せるようにし、同一ステータスコードに複数のコンテンツタイプが定義されている場合(コンテントネゴシエーション)の誤判定を解消する。変更内容
OpenApiResponseValidator::validate()にオプションパラメータ?string $responseContentType = nullを追加(後方互換)normalizeMediaType(),isContentTypeInSpec(),isJsonContentType()ヘルパーメソッドを追加ValidatesOpenApiSchematrait の$hasNonJsonContentTypeガード処理をバリデータ側に移動し、Content-Type をバリデータに渡すように変更関連情報