Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#8,699 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
openapi, php
Ambito
api

Direzione di ricerca

Inizia da JsonApi\JsonSchema\SchemaFactory::buildSchema() e trova la definizione di COLLECTION_BASE_SCHEMA_NAME_NO_PAGINATION, dove data è dichiarato come type: array senza items. Riproduci con bin/console api:openapi:export sull'esempio Book e verifica l'output con un validatore OpenAPI 3.0. È completato quando data ha uno schema items (ad esempio {"type": "object"}), il documento 3.0 risulta valido e i test dello schema JSON:API esistenti continuano a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
PHP
Stelle
2.6k
Fork
989
Merge medio
1g 22h
PR unite (30g)
100

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di api-platform/core

Tutte le issue di api-platform/core

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.