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

[Metadata] Incorrect api schema for path variable

Abierto
#8,646 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
68/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php
Área
api

Línea de trabajo

Start at src/Metadata/Resource/Factory/LinkFactory.php, in the public completeLink method, where uriTemplate path variables become Link objects; follow how the linked resource class/property is resolved and how Link schema is consumed when building OpenAPI path parameters. Reproduce with the #[Get('entities/{id}')] example from the issue and inspect the generated OpenAPI/Swagger JSON for the id path parameter. Done means the path parameter schema reflects the property's type/format, covered by tests around LinkFactory or OpenAPI generation; note the maintainer's pending answer on bug-vs-feature and which schema fields to carry over.

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

Descripción

API Platform version(s) affected: 5.0.2

Description
I noticed that all path variables have the default schema ['type' => 'string'], even when the variable is linked to a class property that does have a type / format.
This means that the swagger-ui will display it as a string input field, and miss the correct validation.

How to reproduce

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Get;

#[Get('entities/{id}')]
readonly class Entity
{
    public function __construct(
        #[ApiProperty(identifier: true)]
        public int $id,
    ) {
    }
}
SwaggerUI Image

Possible Solution
The ApiPlatform\Metadata\Resource\Factory\LinkFactory class is used to generate Link instances based on things like the Operation's uriTemplate.
Here I can use the propertyMetadataFactory to get the schema of the linked property.

Questions
Is this something that should be fixed/implemented at all? For me this would save me from having to add the uriVariables parameter with Link classes everytime.

Is this considered a bug (pull request towards 5.0 branch), or a missing feature (pull request towards main branch?

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

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.