-
-
Notifications
You must be signed in to change notification settings - Fork 962
Fields missing in definition of the schema #3608
Copy link
Copy link
Closed
Description
API Platform version(s) affected: 2.5.5, 2.5.6
Description
It looks like the schema definitions is wrongly generated. For example I have used the api-platform/demo. When using version 2.5.4 or lower below is the schema for the entity Review
{
"hydra:member":[
{
"@context":"string",
"@id":"string",
"@type":"string",
"body":"string",
"rating":0,
"book":{
"@context":"string",
"@id":"string",
"@type":"string",
"title":"string"
},
"author":"string",
"publicationDate":"2020-06-17T11:40:51.078Z"
}
],
"hydra:totalItems":0,
"hydra:view":{
"@id":"string",
"@type":"string",
"hydra:first":"string",
"hydra:last":"string",
"hydra:next":"string"
},
"hydra:search":{
"@type":"string",
"hydra:template":"string",
"hydra:variableRepresentation":"string",
"hydra:mapping":[
{
"@type":"string",
"variable":"string",
"property":"string",
"required":true
}
]
}
}
When using version 2.5.5 or 2.5.6 below is the schema definition for the Review entity.
{
"hydra:member":[
{
"@context":"string",
"@id":"string",
"@type":"string",
"body":"string",
"rating":0,
"author":"string",
"publicationDate":"2020-06-17T11:41:56.932Z"
}
],
"hydra:totalItems":0,
"hydra:view":{
"@id":"string",
"@type":"string",
"hydra:first":"string",
"hydra:last":"string",
"hydra:next":"string"
},
"hydra:search":{
"@type":"string",
"hydra:template":"string",
"hydra:variableRepresentation":"string",
"hydra:mapping":[
{
"@type":"string",
"variable":"string",
"property":"string",
"required":true
}
]
}
}
The ManyToOne relation between the entities is not represented correctly, 'book' is missing here.
How to reproduce
You can use the api-platform/demo. Update composer to use api-platform/core versions 2.5.5 or 2.5.6
Possible Solution
I have looked up a little bit, it seems like it is issue in the file src/JsonSchema/TypeFactory.php and lines 157 to 162. If these lines are commented then the schema is displayed correctly.
if (\array_key_exists('$ref', $jsonSchema)) {
return [
'nullable' => true,
'anyOf' => [$jsonSchema],
];
}
Reactions are currently unavailable