[QueryParameter] Support PHP backed enums in OpenAPI schemas
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Start with how QueryParameter schemas are turned into OpenAPI output and how query values are validated, since the payload names neither file nor test. Check whether the existing enum handling for resource properties can be reused for a QueryParameter schema that names an enum class. The syntax is still open (a 'enumClass' key inside schema, or a dedicated option), so agree on it with maintainers first. Done means the generated schema lists the backed enum's values and incoming values are validated against them.
索引モデルが issue の本文から書いたものです。
説明
Description
In API Platform 4.4 / 5.0, defining a QueryParameter with allowed values from a PHP backed enum requires manually duplicating its values in the OpenAPI schema.
For example:
enum FooEnum: string
{
case A = 'a';
case B = 'b';
case C = 'c';
}
Currently, the values must be explicitly listed:
new QueryParameter(
schema: [
'type' => 'string',
'enum' => ['a', 'b', 'c'],
],
)
This duplicates the enum definition and requires updating the schema whenever enum cases change.
PHP does not allow calling FooEnum::cases() directly in attribute arguments.
Proposed solution
Allow referencing a PHP backed enum class directly in a QueryParameter schema.
For example:
new QueryParameter(
schema: [
'type' => 'string',
'enumClass' => FooEnum::class,
],
)
Alternatively, a dedicated enumClass option on QueryParameter could be introduced.
The syntax is illustrative; the goal is to avoid manually duplicating enum values.
Expected behavior
API Platform should automatically:
- Extract backed enum values using
FooEnum::cases(). - Include these values in the generated OpenAPI schema.
- Validate incoming parameter values against the enum.
Generated OpenAPI schema:
type: string
enum:
- a
- b
- c
Automatic conversion to PHP enum instances is not required as part of this feature.
Additional context
API Platform already supports PHP backed enums in resource properties and OpenAPI schema generation.
It would be useful to provide equivalent support for explicitly declared query parameters, keeping the enum as the single source of truth.
- 主要言語
- PHP
- スター
- 2.6k
- フォーク
- 989
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 90
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
api-platform/core のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
api-platform/core#8690 ·
メンテナーはふだん 1 日以内に返信
-
SkolemIriConverter isn't reset between requests in worker mode (missing kernel.reset tag)対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
api-platform/core#8680 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 54/100
api-platform/core#8664 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Metadata] Incorrect api schema for path variable対応中かも @bram123 が 3 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
api-platform/core#8646 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
HTTP cache purgers error handling and performance issues対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
api-platform/core#8591 ·
メンテナーはふだん 1 日以内に返信
api-platform/core の issue をすべて見る
似ている issue
-
HttpRequestTrait fatals on WordPress 7.2: $blocked_http_requests clashes with WP_UnitTestCase_Baseオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
pluginsGLPI/addressing#127 ·