Fields missing in definition of the schema
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],
];
}
I'm having the same Issue and I would like to add something:
If we open the schema on swagger (instead of the json example), the field is visible.
If we unfold it, it shows anyOf -> ClassName:jsonld-groups > {...}
Which seems highly related to @freakheart 's code block and to the anyOf feature.
I confirm I've got the same issue. Edit: This happens in my case with variable with a _ in the name for example $provider_reference doesn't work but $providerReference does work. @freakheart & @bachinblack do you have this exact same situation?
It's been so long I had completely forgotten about this issue.
@freakheart & @bachinblack do you have this exact same situation?
No, it failed with every embedded object, no matter the name they were given.
I had a dirty workaround on a SwaggerDecorator to remove anyOf but I'm now running 2.6.3 and the issue seems gone.
That said, I've had some troubles with snake_case and symfony/api_platform in the past. I think it had to do with serialization. I would recommend using camelCase, if it's all the same to you.
You should look at #1554, where they talk about it.
any field with the _ in the variable makes it disappear from the swagger. not sure why is that happening. but honestly i dont like naming my variables like this myVariable i rather prefer my_variable just makes it more readable. i am on the latest version of the api. at the time of writing this comment. any work around would be helpful. also i the cases when it does shoes the variables which are my_variable the schema will also have myVariable property the underscore version says its ( readonly ). so i wonder if its just a parsing issue or the way its creating the schema in. other words.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.