JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`
Maintainer antworten meist innerhalb von 2 Tagen
Ein zugehöriger Pull Request wurde bereits gemerged.
- #8724 von @ousamabenyounes — gemerged
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- Unter einer Stunde
- Anfängerfreundlichkeit
- 80/100
Rechercherichtung
Das Problem wird im Issue genannt: JsonApi\JsonSchema\SchemaFactory::buildSchema(), wo Item-Definitionen ihre properties zugewiesen bekommen. Lies diese Methode und füge dann type mit dem Wert object direkt neben dieser Zuweisung hinzu, aber nur für die Item-Schemas. Fertig ist es, wenn die exportierte Spezifikation aus bin/console api:openapi:export "type": "object" bei Book.jsonapi, Order.jsonapi, Order.OrderInput.jsonapi und OrderLine.jsonapi zeigt und die bestehenden Tests für JSON:API-Schemas weiterhin bestehen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
API Platform version(s) affected
4.4.4
Description
The JSON:API resource document schemas, such as Book.jsonapi and the input schemas like Order.OrderInput.jsonapi, have only a properties key at the top level. They have no type: object.
A schema without type also accepts a string, number, array or null, because properties applies only to objects. Validators and fuzzers that generate requests from the spec (for example Schemathesis) then send bodies like "foo" or 42, which the API never accepts. The nested data objects already declare "type": "object". Only the top level is missing it.
How to reproduce
Any resource with the jsonapi format shows it, for example the Book resource from #8699. Generated schema:
"Book.jsonapi": {
"properties": {
"data": { "type": "object", "properties": { "...": "..." } }
}
}
In a minimal app with the resources from #8698 and #8699, these four schemas have no type: Book.jsonapi, Order.jsonapi, Order.OrderInput.jsonapi, OrderLine.jsonapi.
Expected: every *.jsonapi document schema declares "type": "object".
Possible Solution
In JsonApi\JsonSchema\SchemaFactory::buildSchema(), set $definitions[$definitionName]['type'] = 'object' next to the properties assignment for item schemas.
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.)
- 109
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 12 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
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
api-platform/core#8816 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 66/100
api-platform/core#8815 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 55/100
api-platform/core#8814 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in api-platform/core
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 69/100
opnsense/core#11171 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
getgrav/grav-plugin-form#664 ·
-
claude
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
sprain/sprainocchio#26 ·
-
sync-en
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag
-
sync-en
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag