Skip to content

New Feature: #[OpenApiSpec] Attribute によるスペック名の宣言的指定#31

Merged
wadakatu merged 6 commits intomainfrom
feat/openapi-spec-attribute
Mar 16, 2026
Merged

New Feature: #[OpenApiSpec] Attribute によるスペック名の宣言的指定#31
wadakatu merged 6 commits intomainfrom
feat/openapi-spec-attribute

Conversation

@wadakatu
Copy link
Collaborator

概要

PHP Attribute #[OpenApiSpec] を使って、テストクラスやテストメソッドに対して宣言的に OpenAPI スペック名を指定できるようにしました。従来の openApiSpec() メソッドオーバーライドも引き続き動作します。

変更内容

  • #[OpenApiSpec('spec-name')] Attribute クラスを追加(クラス・メソッド両方に対応)
  • ValidatesOpenApiSchema trait に resolveOpenApiSpec() メソッドを追加し、以下の優先順位でスペック名を解決:
    1. テストメソッドの #[OpenApiSpec] Attribute
    2. テストクラスの #[OpenApiSpec] Attribute
    3. openApiSpec() メソッドのオーバーライド
    4. config('openapi-contract-testing.default_spec')
  • エラーメッセージに #[OpenApiSpec] の使用案内を追記
  • クラスレベル・メソッドレベルの Attribute 解決テストを追加

関連情報

  • 既存の openApiSpec() オーバーライドは完全に後方互換
  • PHPUnit 11-13 すべてで動作確認済み

…lution

Introduce a PHP Attribute that allows test classes and methods to
declaratively specify which OpenAPI spec to validate against, instead
of relying solely on openApiSpec() overrides or the config default.

Resolution priority: method attribute > class attribute > openApiSpec()
override > config default_spec.
…agnostic use

Extract OpenApiSpec attribute from Laravel namespace to
Studio\OpenApiContractTesting and introduce OpenApiSpecResolver trait
with an openApiSpecFallback() hook. The Laravel trait now composes
OpenApiSpecResolver and overrides the fallback for config-based defaults.
…mous classes

Replace anonymous class stubs in CreatesTestResponse with
Symfony\Component\HttpFoundation\Response, fixing 3 PHPStan errors
(missing generics, type mismatch, iterable type) at the root cause
rather than suppressing them via ignore rules.
Widen from ^8.0 (PHP 8.4+ only) to ^6.4 || ^7.0 || ^8.0 so the
package can be installed on PHP 8.2 and 8.3 in the CI matrix.
@wadakatu wadakatu merged commit 9936918 into main Mar 16, 2026
8 checks passed
@wadakatu wadakatu deleted the feat/openapi-spec-attribute branch March 16, 2026 13:03
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.

1 participant