Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

OpenAPI missing request schema when providing MediaType examples

Đã đóng
#8,661 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
openapi, php
Lĩnh vực
api

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
PHP
Star
2.6k
Fork
989
Merge trung bình
1 ngày 22 giờ
Pull request đã merge (30 ngày)
100

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của api-platform/core

Tất cả issue của api-platform/core

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.