Skip to content

JSON:API: JsonApiCollectionBaseSchemaNoPagination declares data as type: array without items #8699

Closed

Description

@aszenz

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.

Activity

  1. added 2 commits that reference this issue on Oct 19, 2026
    f29d796
    82496b3
  2. soyuka commented on Oct 19, 2026

    @soyuka
    Member

    fixed by #8727, will be in the next 5.0 patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions