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

SortFilter generates unsupported array form for parameters

Abierto Apto para principiantes
#8,744 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
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php

Línea de trabajo

Empieza leyendo SortFilter y OpenApiFilterTrait::getOpenApiParameters() y luego revisa las pruebas de los parámetros de consulta OpenAPI generados. El informe identifica castToArray como el probable origen del parámetro adicional con formato de array. Se considera terminado cuando la documentación ya no anuncia orderDate[] si el filtro rechaza esa entrada y pasan las pruebas pertinentes.

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

Descripción

API Platform version(s) affected:
I have tested this on both api-platform/core 4.4.4 and api-platform/core 5.0.3

Description
When you add a SortFilter to an endpoint it generates 2 forms of the sortFilter for the given property. For example:

Let's create the following Collection endpoint:

#[ApiResource(
    shortName: 'Party',
    operations: [
        new GetCollection(
            '/activities/parties{._format}',
            parameters: [
                'orderDate' => new QueryParameter(
                    filter: new SortFilter(),
                    property: 'date',
                ),
            ]
        ),
    ],
    openapi: new Operation(
        tags: ['Activities'],
        summary: 'Parties',
    )
)]

This would result in the docs.jsonopenapi generating these two parameters for it:

{
            "name": "orderDate",
            "in": "query",
            "description": "Party orderDate",
            "required": false,
            "deprecated": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc",
                "ASC",
                "DESC"
              ]
            },
            "style": "form",
            "explode": true
          },
          {
            "name": "orderDate[]",
            "in": "query",
            "description": "Party orderDate",
            "required": false,
            "deprecated": false,
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "asc",
                  "desc",
                  "ASC",
                  "DESC"
                ]
              }
            },

The first works fine, but if you were to use ?orderDate[]= the endpoint will throw a constrain violation with code 422 saying the selected value is not valid. It seems Order filter creates the documentation for it but does not actually support this form of the filter (which makes sense to me as I cannot come up with a situation where you would want to be able to sort the same property in multiple directions).

How to reproduce
I think the previous header explains it adequately.

Possible Solution
One solution would be to overwrite the castToArray property of the parameter before passing it to OpenApiFilterTrait's getOpenApiParameters() method by altering the use statement in SortFilter to something like:

use OpenApiFilterTrait {
        getOpenApiParameters as private traitGetOpenApiParameters;
    }

and then setting castToArray to false if it was NULL by adding the following to SortFilter:

public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null
    {
        return $this->traitGetOpenApiParameters(
            $parameter->withCastToArray(
                $parameter->getCastToArray() ?? false,
            )
        );
    }
Lenguaje dominante
PHP
Estrellas
2.6k
Forks
988
Merge medio
1 d 19 h
PR fusionados (30 d)
106

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.