Closed
Description
API Platform version(s) affected: 2.6.3
Description
Let's assume we have this two models:
/**
* @ApiResource
*/
class Cart
{
protected string $id = 'an-identifier';
protected ?ShippingAddress $shippingAddress = null;
}
class ShippingAddress
{
protected string $street = 'street';
}
Note: Only Cart
is registered as Api Platform resource, ShippingAddress
is only an embedded object.
Currently, the generated json schema looks like this:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/Cart.jsonld",
"definitions": {
"Cart.jsonld": {
"type": "object",
"properties": {
"@context": {
"readOnly": true,
"type": "string"
},
"@id": {
"readOnly": true,
"type": "string"
},
"@type": {
"readOnly": true,
"type": "string"
},
"id": {
"readOnly": true,
"type": "string",
"format": "uuid"
},
"shippingAddress": {
"nullable": true,
"anyOf": [
{
"$ref": "#/definitions/ShippingAddress.jsonld"
}
]
}
}
},
"ShippingAddress.jsonld": {
"type": "object",
"properties": {
"@context": {
"readOnly": true,
"type": "string"
},
"@id": {
"readOnly": true,
"type": "string"
},
"@type": {
"readOnly": true,
"type": "string"
},
"street": {
"type": "string"
}
}
}
}
}
The Cart.shippingAddress
part is not a valid json schema, it must be:
"shippingAddress": {
"type": ["object", "null"],
"anyOf": [
{
"$ref": "#/definitions/ShippingAddress.jsonld"
}
]
}
How to reproduce
Create the two models above and run php bin/console api:json-schema:generate 'Cart'
to get the Json Schema.
Additional Context
The unit test for
core/src/JsonSchema/TypeFactory.php
Line 52 in 4717bd5
core/tests/JsonSchema/TypeFactoryTest.php
Lines 32 to 36 in 4717bd5
is twisted because it doesn't test by providing the value of
$readableLink
, which is true
in our case.