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

JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`

Đang mở Phù hợp với người mới
#8,701 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

@ousamabenyounes đang làm issue này rồi.

Từ ngày 16/10/2026.

  • #8724 của @ousamabenyounes — đang mở

Đá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
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ệ
openapi, php
Lĩnh vực
api

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

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.