Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

JSON:API: `JsonApiCollectionBaseSchemaNoPagination` declares `data` as `type: array` without `items`

オープン 初心者向け
#8,699 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
openapi, php
領域
api

調査の方向性

JsonApi\JsonSchema\SchemaFactory::buildSchema() から始めて、COLLECTION_BASE_SCHEMA_NAME_NO_PAGINATION の定義を見つけてください。そこでは data が items なしの type: array として宣言されています。Book の例で bin/console api:openapi:export を実行して問題を再現し、出力を OpenAPI 3.0 バリデーターで確認してください。data に items スキーマ(例:{"type": "object"})があり、3.0 ドキュメントが検証を通り、既存の JSON:API スキーマテストがすべて引き続きパスすれば完了です。

索引モデルが issue の本文から書いたものです。

説明

API Platform version(s) affected

4.4.4

Description

When pagination is disabled on a GetCollection operation, the JSON:API collection response refers to JsonApiCollectionBaseSchemaNoPagination. In that schema, data is {"type": "array"} with no items.

OpenAPI 3.0 requires items when type is array, so 3.0 validators and some code generators reject the document. In 3.1 and 3.2 the schema is valid, but it says nothing about the members.

How to reproduce
#[ApiResource(operations: [
    new Get(provider: [self::class, 'provide']),
    new GetCollection(paginationEnabled: false, provider: [self::class, 'provideAll']),
])]
final class Book
{
    public function __construct(public int $id = 1, public string $title = 'Dune') {}
    public static function provide(): self { return new self(); }
    /** @return list<self> */
    public static function provideAll(): array { return [new self()]; }
}

Generated schema (shortened):

"JsonApiCollectionBaseSchemaNoPagination": {
  "type": "object",
  "properties": {
    "links": { "...": "..." },
    "meta": { "...": "..." },
    "data": { "type": "array" }
  },
  "required": ["data"]
}

Expected: data has an items schema, for example {"type": "object"}. The concrete collection schema can still narrow it with allOf.

Possible Solution

Add 'items' => ['type' => 'object'] to data in the COLLECTION_BASE_SCHEMA_NAME_NO_PAGINATION definition in JsonApi\JsonSchema\SchemaFactory::buildSchema().

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.

主要言語
PHP
スター
2.6k
フォーク
989
平均マージ
2日 1時間
マージ済み PR(30日)
104

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

api-platform/core のほかの issue

api-platform/core の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。