JSON:API: `JsonApiCollectionBaseSchemaNoPagination` declares `data` as `type: array` without `items`
Maintainer antworten meist innerhalb von 2 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 82/100
Rechercherichtung
Beginne in JsonApi\JsonSchema\SchemaFactory::buildSchema() und suche die Definition von COLLECTION_BASE_SCHEMA_NAME_NO_PAGINATION, in der data als type: array ohne items deklariert ist. Reproduziere das Problem mit bin/console api:openapi:export am Book-Beispiel und prüfe die Ausgabe mit einem OpenAPI-3.0-Validator. Fertig ist es, wenn data ein items-Schema hat (zum Beispiel {"type": "object"}), das 3.0-Dokument validiert und die bestehenden JSON:API-Schematests weiterhin laufen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- PHP
- Sterne
- 2.6k
- Forks
- 988
- Ø Merge
- 4 T. 10 Std.
- Gemergte PRs (30 T.)
- 92
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus api-platform/core
-
API Platform ignores array shapes in the JSON SchemaEvtl. vergeben @afraca hat das vor 9 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
api-platform/core#8766 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
api-platform/core#8744 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 Unter einer Stunde Anfängerfreundlichkeit 80/100
api-platform/core#8701 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 30/100
api-platform/core#8791 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Preserve exact SearchFilter behaviour for Doctrine collection associations with QueryParameterOffen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
api-platform/core#8790 ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in api-platform/core
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 74/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Automattic/blocks-engine#4355 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
agentic bug complete-verify
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
MagnaCapax/PMSS#1234 ·
Maintainer antworten meist innerhalb von 3 Tagen