[QueryParameter] Support PHP backed enums in OpenAPI schemas
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- PHP
- Sterne
- 2.6k
- Forks
- 989
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 90
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus api-platform/core
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
api-platform/core#8690 ·
Maintainer antworten meist innerhalb von 1 Tag
-
SkolemIriConverter isn't reset between requests in worker mode (missing kernel.reset tag)Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
api-platform/core#8680 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 54/100
api-platform/core#8664 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Metadata] Incorrect api schema for path variableEvtl. vergeben @bram123 hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
api-platform/core#8646 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
HTTP cache purgers error handling and performance issuesEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 38/100
api-platform/core#8591 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in api-platform/core
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
Automattic/blocks-engine#2866 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement good first issue help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
backend gamification P0
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
semanadeinformatica/website#461 ·
-
HttpRequestTrait fatals on WordPress 7.2: $blocked_http_requests clashes with WP_UnitTestCase_BaseOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
area: docs eco: php good first issue help wanted lane: free-agent roadmap size: XS type: docs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
arminazimi/evergreen#453 ·
Maintainer antworten meist innerhalb von 1 Tag