ExactFilter on enum typed property is not generating enums in docs.jsonopenapi
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 55/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 领域
- 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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
api-platform/core 的其他 Issue
-
API Platform ignores array shapes in the JSON Schema可能已有人在做 @afraca 于 11 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
api-platform/core#8766 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
api-platform/core#8744 ·
维护者通常 2 天内回复
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1 小时以内 新手友好度 80/100
api-platform/core#8701 ·
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
api-platform/core#8819 ·
维护者通常 2 天内回复
-
难度 3/5 1-2 天 新手友好度 66/100
api-platform/core#8815 ·
维护者通常 2 天内回复
查看 api-platform/core 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
endoflife-date/endoflife.date#11561 ·
维护者通常 1 天内回复
-
good first issue priority:low type:bug
难度 2/5 1-3 小时 新手友好度 78/100
crazy-goat/fdb-php#184 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
nextcloud/groupfolders#5218 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
nextcloud/sharelisting#624 ·
-
`wp theme mod set` prints its failure message as `Success` and exits 0可能已有人在做 @dhrupo 今天认领。 未关闭bug command:theme-mod-set status:unconfirmed
难度 2/5 1-3 小时 新手友好度 82/100
wp-cli/extension-command#570 ·