JSON:API: `included` schema is `items: {anyOf: []}` when a relation points to a resource without operations (`NotExposed`)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
api-platform/core のほかの issue
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`対応中かも @ousamabenyounes が 2 日前に担当しました。 オープン
難易度 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 日以内に返信
-
[Json-Schema] Nested resources lost externalDoc and description data対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
api-platform/core#8721 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 50/100
api-platform/core#8704 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
api-platform/core#8703 ·
メンテナーはふだん 1 日以内に返信
api-platform/core の issue をすべて見る
似ている issue
-
ObjectMapper
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
symfony/symfony-docs#23390 ·
メンテナーはふだん 2 日以内に返信
-
sync-en
難易度 1/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
sync-en
難易度 1/5 1時間未満 初心者へのやさしさ 83/100
メンテナーはふだん 3 日以内に返信
-
Перевод устарел
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信