JSON:API: 404/405 router errors are empty, and error objects have a non-spec `type` member
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- PHP
- スター
- 2.6k
- フォーク
- 989
- 平均マージ
- 2日 1時間
- マージ済み PR(30日)
- 104
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
api-platform/core のほかの issue
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`対応中かも @ousamabenyounes が 1 日前に担当しました。 オープン
難易度 2/5 1時間未満 初心者へのやさしさ 80/100
api-platform/core#8701 ·
メンテナーはふだん 1 日以内に返信
-
JSON:API: `JsonApiCollectionBaseSchemaNoPagination` declares `data` as `type: array` without `items`オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
api-platform/core#8699 ·
メンテナーはふだん 1 日以内に返信
-
api:openapi:export --spec-version=3.0.0 outputs `webhooks`, which is invalid in OpenAPI 3.0対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
api-platform/core#8690 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
api-platform/core#8680 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
api-platform/core#8725 ·
メンテナーはふだん 1 日以内に返信
api-platform/core の issue をすべて見る
似ている issue
-
PHP workflow streaming requests buffer the full SSE response対応中かも @Winoren が今日担当しました。 オープンreview: medium
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
langgenius/dify#44270 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug customer-reported
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
MagnaCapax/PMSS#1085 ·
メンテナーはふだん 5 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
nunomaduro/collision#375 ·
-
enhancement good first issue hacktoberfest help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
thetheago/laravel-seeder-versioning#19 ·
メンテナーはふだん 1 日以内に返信