Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

OpenAPI missing request schema when providing MediaType examples

Aperta
#8,661 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
openapi, php
Ambito
api

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?

Lingua principale
PHP
Stelle
2.6k
Fork
987
Merge medio
1g 7h
PR unite (30g)
84

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di api-platform/core

Tutte le issue di api-platform/core

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.