Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

OpenAPI missing request schema when providing MediaType examples

Abierto
#8,661 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
openapi, php
Área
api

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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?

Lenguaje dominante
PHP
Estrellas
2.6k
Forks
987
Merge medio
1 d 7 h
PR fusionados (30 d)
84

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de api-platform/core

Todos los issues de api-platform/core

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.