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

SortFilter generates unsupported array form for parameters

Aperta Adatta ai principianti
#8,744 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à
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php

Direzione di ricerca

Inizia leggendo SortFilter e OpenApiFilterTrait::getOpenApiParameters(), poi controlla i test per i parametri di query OpenAPI generati. Il report indica castToArray come probabile origine del parametro aggiuntivo in formato array. Il lavoro è terminato quando la documentazione non pubblicizza più orderDate[] se il filtro rifiuta quell’input e i test pertinenti passano.

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

Descrizione

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,
            )
        );
    }
Lingua principale
PHP
Stelle
2.6k
Fork
988
Merge medio
1g 19h
PR unite (30g)
105

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.