JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 80/100
Hướng nghiên cứu
Issue đã nêu rõ chỗ cần sửa: JsonApi\JsonSchema\SchemaFactory::buildSchema(), nơi các định nghĩa item được gán properties. Hãy đọc phương thức đó, sau đó thêm type với giá trị object ngay bên cạnh phép gán đó, chỉ áp dụng cho schema của item. Công việc hoàn thành khi spec xuất ra bởi bin/console api:openapi:export hiển thị "type": "object" trên Book.jsonapi, Order.jsonapi, Order.OrderInput.jsonapi và OrderLine.jsonapi, và các test schema JSON:API hiện có vẫn pass.
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 resource document schemas, such as Book.jsonapi and the input schemas like Order.OrderInput.jsonapi, have only a properties key at the top level. They have no type: object.
A schema without type also accepts a string, number, array or null, because properties applies only to objects. Validators and fuzzers that generate requests from the spec (for example Schemathesis) then send bodies like "foo" or 42, which the API never accepts. The nested data objects already declare "type": "object". Only the top level is missing it.
How to reproduce
Any resource with the jsonapi format shows it, for example the Book resource from #8699. Generated schema:
"Book.jsonapi": {
"properties": {
"data": { "type": "object", "properties": { "...": "..." } }
}
}
In a minimal app with the resources from #8698 and #8699, these four schemas have no type: Book.jsonapi, Order.jsonapi, Order.OrderInput.jsonapi, OrderLine.jsonapi.
Expected: every *.jsonapi document schema declares "type": "object".
Possible Solution
In JsonApi\JsonSchema\SchemaFactory::buildSchema(), set $definitions[$definitionName]['type'] = 'object' next to the properties assignment for item schemas.
Additional Context
Checked on api-platform/core v4.4.4, Symfony 7.4, PHP 8.5, in an empty Symfony app. The code of JsonApi\JsonSchema\SchemaFactory on main is the same as in v4.4.4.
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']],
'docs_formats' => ['jsonopenapi' => ['application/vnd.openapi+json']],
'doctrine' => ['enabled' => false],
]);
The spec comes from bin/console api:openapi:export.
- Ngôn ngữ chính
- PHP
- Star
- 2.6k
- Fork
- 989
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 102
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: `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
-
[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
Tất cả issue của api-platform/core
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
grokability/snipe-it#19857 ·
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 92/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Authentication / Authorization Feature: Volunteer
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
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 64/100
WordPress/mcp-adapter#399 ·
Maintainer thường phản hồi trong vòng 1 ngày