ExactFilter on enum typed property is not generating enums in docs.jsonopenapi

Aperta
#8,816 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
openapi, php, symfony
Ambito
api, documentation

Direzione di ricerca

Start by reading the QueryParameter and ExactFilter documentation generation paths, then compare the reported OpenAPI schemas for the legacy BackedEnumFilter and the new ExactFilter parameter. Identify where enum types are inferred for parameter schemas and check the relevant tests; done means enum values from an enum typed property appear in the generated schema for the new parameter.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

API Platform version(s) affected: 4.4.3

Description
I'm rewriting the legacy ApiFilter BackedEnumFilter to a #[QueryParameter] attribute using the ExactFilter that is kept in 6.0 (see this documentation: https://api-platform.com/docs/core/upgrade-guide/#legacy-doctrine-filters). The filter works but the enums are not generated anymore (which means the dropdown with available values is lost on the SwaggerUI). Now a normal text input is given which is not desired for our UI.

How to reproduce
So the old situation was:
#[ApiFilter(BackedEnumFilter::class, properties: ['type'])]
This generated the enums belonging to this type property in the docs.jsonopenapi of our api

In the new situation a QueryParameter is used with ExactFilter:

#[ApiResource(
    operations: [
        new GetCollection(
            '/activiteiten/bijeenkomsten{._format}',
            parameters: [
                'type' => new QueryParameter(
                    filter: new ExactFilter(),
                    property: 'type',
                ),
            ]
        ),
    ],
)]

And type in this Entity is the following:

#[ORM\Column(name: 'act_type', type: Types::ENUM)]
private TypeEnum $type;

Filtering like this works when the user correctly inputs an enum value but the enums are not generated anymore in the docs.jsonopenapi

Possible Solution
Adding

schema: [
        'type' => 'string',
        'enum' => array_column(TypeEnum::cases(), 'value'),
    ],

to the requestParameter to retrieve the values of the enums here for the dropdown is not possible since only constant values can be given here.

Another idea is creating a custom filter and using the getOpenApiParameters() function to document the filter, but this seem #s impossible because ExactFilter is a final class.

Additional Context
This was the json in our docs.jsonopenapi:
{ "name": "type", "in": "query", "description": "", "required": false, "deprecated": false, "schema": { "type": "string", "enum": [ "cursus", "opleiding", "clinic", "themabijeenkomst", "clusterbijeenkomst", "symposium", "congres", "regioraad", "bondsraad", "officialbijeenkomst", "kaderbijeenkomst", "webinar", "workshop", "e-learning", "bijscholing" ] }, "style": "form", "explode": false }, { "name": "type[]", "in": "query", "description": "", "required": false, "deprecated": false, "schema": { "type": "array", "items": { "type": "string", "enum": [ "cursus", "opleiding", "clinic", "themabijeenkomst", "clusterbijeenkomst", "symposium", "congres", "regioraad", "bondsraad", "officialbijeenkomst", "kaderbijeenkomst", "webinar", "workshop", "e-learning", "bijscholing" ] } }, "style": "form", "explode": true },

And this is the json now with the Exactfilter in the QueryParameter:
{ "name": "type", "in": "query", "description": "Bijeenkomst type", "required": false, "deprecated": false, "schema": { "type": "string" }, "style": "form", "explode": true }, { "name": "type[]", "in": "query", "description": "Bijeenkomst type", "required": false, "deprecated": false, "schema": { "type": "array", "items": { "type": "string" } }, "style": "deepObject", "explode": true },

Which misses the enum in the schema attribute

THIS ISSUE WAS ALSO POSTED IN THE api-platform/api-platform REPOSITORY
https://github.com/api-platform/api-platform/issues/3017

Lingua principale
PHP
Stelle
2.6k
Fork
988
Merge medio
4g 10h
PR unite (30g)
114

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di api-platform/core

Tutte le issue di api-platform/core

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.