Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

SortFilter generates unsupported array form for parameters

Đang mở Phù hợp với người mới
#8,744 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
api, backend-api-design

Hướng nghiên cứu

Bắt đầu bằng cách đọc SortFilter và OpenApiFilterTrait::getOpenApiParameters(), sau đó kiểm tra các bài kiểm thử cho tham số truy vấn OpenAPI được tạo. Báo cáo xác định castToArray là nguyên nhân có khả năng cao dẫn đến tham số dạng mảng thừa. Công việc được xem là hoàn tất khi tài liệu không còn quảng bá orderDate[] nếu bộ lọc từ chối đầu vào đó và các bài kiểm thử liên quan đều đạt.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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,
            )
        );
    }
Ngôn ngữ chính
PHP
Star
2.6k
Fork
988
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
106

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của api-platform/core

Tất cả issue của api-platform/core

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.