SortFilter generates unsupported array form for parameters
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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của api-platform/core
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`Có thể đã có người làm @ousamabenyounes đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 80/100
api-platform/core#8701 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Json-Schema] Nested resources lost externalDoc and description dataCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
api-platform/core#8721 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
JSON:API: 404/405 router errors are empty, and error objects have a non-spec `type` memberCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 50/100
api-platform/core#8704 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
JSON:API: request documents with no `data`, no `type` or a wrong `type` are accepted with 201Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
api-platform/core#8703 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
JSON:API: relations set through the constructor reject spec resource linkage (`relationships.<name>.data`)Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
api-platform/core#8702 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của api-platform/core
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
verbb/formie#3033 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Type] Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Awaiting Triage enhancement / feature request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
macOS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
beyondcode/herd-community#1774 ·