Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[QueryParameter] Support PHP backed enums in OpenAPI schemas

オープン
#8,686 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
php
領域
api

調査の方向性

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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

api-platform/core のほかの issue

api-platform/core の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。