JSON:API: 404/405 router errors are empty, and error objects have a non-spec `type` member
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 50/100
Hướng nghiên cứu
Start with JsonApi\Serializer\ErrorNormalizer in src/JsonApi/Serializer and reproduce with the Novel resource from the issue. Compare the bodies of GET /nope, DELETE /novels/1 and GET /novels/999 to find where the non-operation errors lose their status, title and detail. Done when the 404 and 405 errors carry the same members as the operation errors, and no error object has a type member while links.type remains.
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
4.4.4
Description
The JSON:API error documents have two problems that remain after #8366 (which makes status a string on main).
-
Errors that do not come from an operation are empty. An unknown route (404) or a method that is not allowed (405) answers with an error object that has only a generated
id. It has nostatus,titleordetail:{"errors":[{"id":"/.well-known/genid/1d2136a82a8b3a05d6a2"}]} -
Error objects have a
typemember. The spec lists the members of an error object (id,links,status,code,title,detail,source,meta), and "Unless otherwise noted, objects defined by this specification or any applied extensions MUST NOT contain any additional members."JsonApi\Serializer\ErrorNormalizercopies the problemtypetolinks.type, which is correct, but it also keeps it as atypemember:{"errors":[{"id":"/errors/404","title":"An error occurred","detail":"Not Found","status":404,"type":"/errors/404","links":{"type":"/errors/404"},"code":"404"}]}
#3042 is about the older problem+json format. These two problems are in the current errors format.
How to reproduce
#[ApiResource(operations: [
new Get(provider: [self::class, 'provide']),
new Post(processor: [self::class, 'process']),
])]
final class Novel
{
public int $id = 1;
public string $title = 'Dune';
public static function provide(): ?self { return null; }
public static function process(self $data, Operation $operation): self { return $data; }
}
| Request | Status | Body |
|---|---|---|
GET /nope |
404 | {"errors":[{"id":"/.well-known/genid/…"}]} |
DELETE /novels/1 |
405 | {"errors":[{"id":"/.well-known/genid/…"}]} |
GET /novels/999 |
404 | {"errors":[{"id":"/errors/404","title":"An error occurred","detail":"Not Found","status":404,"type":"/errors/404","links":{"type":"/errors/404"},"code":"404"}]} |
POST /novels with {"data":{"type":"Novel","attributes":{"title":5}}} |
400 | {"errors":[{"id":"/errors/400","title":"An error occurred","detail":"The type of the \"title\" attribute must be \"string\", \"integer\" given.","status":400,"type":"/errors/400","links":{"type":"/errors/400"},"code":"400"}]} |
Expected:
- The 404 and 405 errors have the same members as the other errors:
status,title,detail,codeandlinks.type. - Error objects have no
typemember. The value stays inlinks.type.
Additional Context
Checked on api-platform/core v4.4.4, Symfony 7.4, PHP 8.5, in an empty Symfony app. The related code in src/JsonApi/Serializer is the same on main, except for the error status cast (#8366).
The app has only FrameworkBundle, TwigBundle and ApiPlatformBundle, with this config:
$c->extension('api_platform', [
'mapping' => ['paths' => ['%kernel.project_dir%/src/ApiResource']],
'formats' => ['jsonapi' => ['application/vnd.api+json']],
'error_formats' => ['jsonapi' => ['application/vnd.api+json'], 'jsonproblem' => ['application/problem+json']],
'doctrine' => ['enabled' => false],
]);
All requests send Accept: application/vnd.api+json and, when they have a body, Content-Type: application/vnd.api+json. The responses are from the prod environment.
- Ngôn ngữ chính
- PHP
- Star
- 2.6k
- Fork
- 989
- Merge trung bình
- 2 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 104
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 hôm nay. Đ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:API: `JsonApiCollectionBaseSchemaNoPagination` declares `data` as `type: array` without `items`Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
api-platform/core#8699 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
api:openapi:export --spec-version=3.0.0 outputs `webhooks`, which is invalid in OpenAPI 3.0Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
api-platform/core#8690 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
api-platform/core#8680 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
api-platform/core#8725 ·
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ự
-
major-release
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 67/100
Intervention/image#1553 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
omegaup/omegaup#10353 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 61/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
effort: low graphiql ide impact: low scope: code quality type: chore
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
wp-graphql/wp-graphql#4486 ·
Maintainer thường phản hồi trong vòng 1 ngày