ExactFilter on enum typed property is not generating enums in docs.jsonopenapi
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Domain
- api, documentation
Research direction
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.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- PHP
- Stars
- 2.6k
- Forks
- 988
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 118
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from api-platform/core
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
api-platform/core#8835 ·
Maintainers usually reply within 2 days
-
API Platform ignores array shapes in the JSON SchemaPossibly taken @afraca claimed this 14 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
api-platform/core#8766 ·
Maintainers usually reply within 2 days
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 Under an hour Newbie friendliness 80/100
api-platform/core#8701 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 57/100
api-platform/core#8834 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
api-platform/core#8832 ·
Maintainers usually reply within 2 days
All issues in api-platform/core
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
bug SH_K
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
McNamara84/ernie#1540 ·
Maintainers usually reply within 1 day
-
Перевод устарел
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
php/frankenphp#2829 ·
Maintainers usually reply within 1 day