Skip to content

Comments

Bugfix: application/problem+json など JSON 互換コンテンツタイプのスキーマバリデーション対応#19

Merged
wadakatu merged 2 commits intomainfrom
fix/json-compatible-content-type-validation
Feb 21, 2026
Merged

Bugfix: application/problem+json など JSON 互換コンテンツタイプのスキーマバリデーション対応#19
wadakatu merged 2 commits intomainfrom
fix/json-compatible-content-type-validation

Conversation

@wadakatu
Copy link
Collaborator

概要

OpenApiResponseValidator::validate()application/json のみをハードコードしていたため、application/problem+jsonapplication/vnd.api+json など JSON 互換のコンテンツタイプで定義されたスキーマがバリデーションされず、常に success が返されていた問題を修正。

変更内容

  • OpenApiResponseValidatorfindJsonSchema() private メソッドを追加し、$responseSpec['content'] 内の全コンテンツタイプを走査して JSON 互換のもの(キーに json を含むもの、大文字小文字区別なし)を探索するように変更
  • content キーが存在するが JSON 互換スキーマが見つからない場合は failure を返すように変更(定義済みコンテンツタイプをエラーメッセージに列挙)
  • content キー自体が存在しない場合(204 等)は従来通り success を返す
  • テストフィクスチャ(petstore-3.0.json / petstore-3.1.json)に application/problem+json のエラーレスポンスを追加
  • 4つの新規テストケースを追加(problem+json の成功/失敗、JSON 非互換タイプの失敗、OAS 3.1 対応)

関連情報

…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
@wadakatu wadakatu merged commit bb5bbea into main Feb 21, 2026
8 checks passed
@wadakatu wadakatu deleted the fix/json-compatible-content-type-validation branch February 21, 2026 04:09
wadakatu added a commit that referenced this pull request Feb 21, 2026
… failing

Fixes a regression introduced in v0.6.0 (PR #19) where endpoints with
non-JSON content types (e.g. text/html) incorrectly returned a failure
result instead of skipping validation. Now returns success when no
JSON-compatible content type is found in the spec.

Fixes #20
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.

bug: application/problem+json レスポンスのスキーマがバリデーションされない

1 participant