Bugfix: application/problem+json など JSON 互換コンテンツタイプのスキーマバリデーション対応#19
Merged
Bugfix: application/problem+json など JSON 互換コンテンツタイプのスキーマバリデーション対応#19
Conversation
…ion/json The validator previously only checked for `application/json` when looking up response schemas. This adds a `findJsonSchema()` method that matches any content type containing "json" (e.g. `application/problem+json`, `application/vnd.api+json`). When content is defined but no JSON-compatible type is found, a descriptive failure is now returned instead of silently skipping validation.
…tching
- Replace str_contains substring match with RFC 6838 structured syntax
suffix matching (=== 'application/json' || str_ends_with('+json'))
- Rename findJsonSchema to findJsonContentType for clearer intent
- Handle JSON content type without schema key (skip validation, matching
prior behavior) instead of producing contradictory error message
- Fix error message terminology: "JSON-compatible response schema"
- Add PHPDoc describing the matching strategy and RFC reference
- Add tests: empty body with problem+json, case-insensitive content type,
schema-less JSON content type, OAS 3.1 non-JSON content type failure
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()がapplication/jsonのみをハードコードしていたため、application/problem+jsonやapplication/vnd.api+jsonなど JSON 互換のコンテンツタイプで定義されたスキーマがバリデーションされず、常にsuccessが返されていた問題を修正。変更内容
OpenApiResponseValidatorにfindJsonSchema()private メソッドを追加し、$responseSpec['content']内の全コンテンツタイプを走査して JSON 互換のもの(キーにjsonを含むもの、大文字小文字区別なし)を探索するように変更contentキーが存在するが JSON 互換スキーマが見つからない場合はfailureを返すように変更(定義済みコンテンツタイプをエラーメッセージに列挙)contentキー自体が存在しない場合(204 等)は従来通りsuccessを返すapplication/problem+jsonのエラーレスポンスを追加関連情報