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

未关闭
#8,816 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
openapi, php, symfony
领域
api, documentation

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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

主要语言
PHP
星标
2.6k
派生
988
平均合并
4 天 10 小时
30 天内合并 PR
114

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

api-platform/core 的其他 Issue

查看 api-platform/core 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。