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

OpenAPI missing request schema when providing MediaType examples

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

Start by reproducing with the EntityResource class and the POST operation's custom openapi RequestBody from the issue, then inspect the generated OpenAPI output for that request body. The bug is that providing MediaType examples drops the schema, so the first question is where the custom MediaType replaces the generated one. Done when the request body keeps the resource schema alongside the examples, and the maintainers have settled whether the merge approach proposed in the issue is acceptable.

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

描述

API Platform version(s) affected: 5.0.2

Description
Documenting requestBody examples removes the request format schemas

How to reproduce
Using the following ApiResource class:


#[Post(
    status: 201,
    openapi: new Operation(
        requestBody: new RequestBody(
            content: new ArrayObject(
                [
                    'application/ld+json' => new MediaType(
                        examples: new ArrayObject(
                            [
                                'hello world' => new Example(description: 'Submitting a "hello world" entity', value: new EntityResource(1, 'Hello world')),
                                'foo bar'     => new Example(description: 'Submitting a "foo bar" entity', value: new EntityResource(2, 'Foo bar')),
                            ],
                        ),
                    ),
                ],
            ),
        ),
    ),
)]
readonly class EntityResource
{
    public function __construct(#[ApiProperty(identifier: true)] public int $id, public string $name)
    {
    }
}

The schema is missing from the generated spec:

SwaggerUI output Image

And I have to add it myself, but this risks documentation drift caused by future API updates.

new ArrayObject(
    [
        'type'       => 'object',
        'properties' => new ArrayObject(
            [
                'id'   => new ArrayObject(['type' => 'integer']),
                'name' => new ArrayObject(['type' => 'string']),
            ],
        ),
    ],
),
SwaggerUI output Image Image

Additional
Would it be possible/okay to merge the API-Platform generated MediaType with the APIResource's MediaType? And only fill in the null values?

主要语言
PHP
星标
2.6k
派生
988
平均合并
1 天 19 小时
30 天内合并 PR
108

环境准备

从这里开始

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

api-platform/core 的其他 Issue

查看 api-platform/core 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

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