[QueryParameter] Support PHP backed enums in OpenAPI schemas
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- PHP
- Estrellas
- 2.6k
- Forks
- 989
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 90
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de api-platform/core
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
api-platform/core#8690 ·
Los mantenedores suelen responder en 1 día
-
SkolemIriConverter isn't reset between requests in worker mode (missing kernel.reset tag)Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
api-platform/core#8680 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 54/100
api-platform/core#8664 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Metadata] Incorrect api schema for path variablePosiblemente ocupada @bram123 la tomó hace 3 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
api-platform/core#8646 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
HTTP cache purgers error handling and performance issuesPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
api-platform/core#8591 ·
Los mantenedores suelen responder en 1 día
Todos los issues de api-platform/core
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Automattic/blocks-engine#2866 ·
Los mantenedores suelen responder en 1 día
-
Good first issue: add laravel-inertia stack budget preset (Laravel 11 + Inertia.js + PHP 8.3)Abiertoenhancement good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
backend gamification P0
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
semanadeinformatica/website#461 ·
-
HttpRequestTrait fatals on WordPress 7.2: $blocked_http_requests clashes with WP_UnitTestCase_BaseAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
area: docs eco: php good first issue help wanted lane: free-agent roadmap size: XS type: docs
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
arminazimi/evergreen#453 ·
Los mantenedores suelen responder en 1 día