Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

SortFilter generates unsupported array form for parameters

Open Beginner friendly
#8,744 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php

Research direction

Start by reading SortFilter and OpenApiFilterTrait::getOpenApiParameters(), then check the tests for generated OpenAPI query parameters. The report identifies castToArray as the likely source of the extra array-form parameter. Done means the docs no longer advertise orderDate[] when the filter rejects that input, with relevant tests passing.

Written by the indexing model from the issue text.

Description

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,
            )
        );
    }
Dominant language
PHP
Stars
2.6k
Forks
988
Avg merge
1d 19h
Merged PRs (30d)
105

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from api-platform/core

All issues in api-platform/core

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.