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

JSON:API: `included` schema is `items: {anyOf: []}` when a relation points to a resource without operations (`NotExposed`)

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

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

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

評価

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

調査の方向性

The empty anyOf comes from JsonApi\JsonSchema\SchemaFactory::buildDefinitionPropertiesSchema(), which skips related classes with false === $hasOperations but still writes anyOf when no reference remains. Reproduce with the two resources in the issue and run bin/console api:openapi:export to inspect Book.jsonapi. Done when included.items is a valid schema (for example {"type": "object"}) or has no empty anyOf, and the exported spec passes validation.

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

説明

API Platform version(s) affected

4.4.4

Description

A resource has a relation to another resource whose only operation is NotExposed. The included property of the JSON:API document schema is then:

"included": { "type": "array", "items": { "anyOf": [] } }

JSON Schema requires anyOf to be a non-empty array, so the document is invalid. Spectral (oas3-schema) and code generators reject it.

The cause looks like JsonApi\JsonSchema\SchemaFactory::buildDefinitionPropertiesSchema(). It skips a related class when false === $hasOperations, but it still writes anyOf when no reference remains.

How to reproduce
#[ApiResource(operations: [new NotExposed()])]
final class Author
{
    public function __construct(public int $id = 1, public string $name = 'Frank Herbert') {}
}

#[ApiResource(operations: [new Get(provider: [self::class, 'provide'])])]
final class Book
{
    public function __construct(public int $id = 1, public string $title = 'Dune', public Author $author = new Author()) {}
    public static function provide(): self { return new self(); }
}

The Book.jsonapi schema:

"included": {
  "description": "Related resources requested via the \"include\" query parameter.",
  "type": "array",
  "items": { "anyOf": [] },
  "readOnly": true
}

Expected: when no related class has a schema reference, included.items is {"type": "object"}, or the anyOf key is left out.

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
平均マージ
1日 22時間
マージ済み PR(30日)
100

環境構築

はじめの一歩

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

api-platform/core のほかの issue

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

似ている issue

PHP の issue をもっと見る

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

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