API Platform ignores array shapes in the JSON Schema

未关闭 适合新手
#8,766 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@afraca 已经在做这个了。

开始于 2026年10月26日。

  • #8767 来自 @afraca —— 未关闭

评估

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

调研方向

首先找到 getJsonSchemaFromType(),并追踪它如何处理 CollectionType;issue 指出该方法最有可能是检查数组结构的地方。确认 PHPDoc array{total: int, processed: int, failed: int} 当前是如何表示的,然后将生成的 schema 与示例中的命名字段进行比较。完成标准是 schema 保留结构中的每个字段及其类型。

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

描述

Description
A property documented with a PHPDoc array shape generates a schema without its field names. The shape becomes a generic map whose value type is the union of all field types. Here you see it going different from what we expect and hope for:

/** @var array{total: int, processed: int, failed: int} */
public array $totals = [];

Example

Before:

totals: { [key: string]: number }

After:

totals: {
  total: number
  processed: number
  failed: number
}

I could drop the whole cause and suggested AI fix here, but don't think anyone wants that...
The gist is, possibly add it in getJsonSchemaFromType(), before the CollectionType branch with if ($type instanceof ArrayShapeType) .

主要语言
PHP
星标
2.6k
派生
987
平均合并
2 天 5 小时
30 天内合并 PR
73

环境准备

从这里开始

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

api-platform/core 的其他 Issue

查看 api-platform/core 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

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