Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Metadata] Incorrect api schema for path variable

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

维护者通常 1 天内回复

@bram123 已经在做这个了。

开始于 2026年10月12日。

  • #8668 来自 @bram123 —— 已关闭,未合并
  • #8677 来自 @bram123 —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
php
领域
api

调研方向

Start at src/Metadata/Resource/Factory/LinkFactory.php, in the public completeLink method, where uriTemplate path variables become Link objects; follow how the linked resource class/property is resolved and how Link schema is consumed when building OpenAPI path parameters. Reproduce with the #[Get('entities/{id}')] example from the issue and inspect the generated OpenAPI/Swagger JSON for the id path parameter. Done means the path parameter schema reflects the property's type/format, covered by tests around LinkFactory or OpenAPI generation; note the maintainer's pending answer on bug-vs-feature and which schema fields to carry over.

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

描述

API Platform version(s) affected: 5.0.2

Description
I noticed that all path variables have the default schema ['type' => 'string'], even when the variable is linked to a class property that does have a type / format.
This means that the swagger-ui will display it as a string input field, and miss the correct validation.

How to reproduce

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Get;

#[Get('entities/{id}')]
readonly class Entity
{
    public function __construct(
        #[ApiProperty(identifier: true)]
        public int $id,
    ) {
    }
}
SwaggerUI Image

Possible Solution
The ApiPlatform\Metadata\Resource\Factory\LinkFactory class is used to generate Link instances based on things like the Operation's uriTemplate.
Here I can use the propertyMetadataFactory to get the schema of the linked property.

Questions
Is this something that should be fixed/implemented at all? For me this would save me from having to add the uriVariables parameter with Link classes everytime.

Is this considered a bug (pull request towards 5.0 branch), or a missing feature (pull request towards main branch?

主要语言
PHP
星标
2.6k
派生
989
平均合并
1 天 23 小时
30 天内合并 PR
102

环境准备

从这里开始

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

api-platform/core 的其他 Issue

查看 api-platform/core 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

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