API Platform version(s) affected: 2.5.1
Description
When allowing to create relations using denormalization_context, the generated Swagger documentation is a list of strings instead of an union of strings and objects.
How to reproduce
It's easy to reproduce the issue on the demo. We have by default the following types (which are already wrong) on the Book entity:
{
//...
"reviews": [
{
"body": "string",
"rating": 0,
"author": "string",
"publicationDate": "2020-03-02T10:31:24.895Z"
}
]
}
but the expected types should be an array of unions (oneOf) of the above type with strings (in the case IRIs are passed).
Now, for the most annoying bug:
In Review, we have the following annotations on body:
/**
* @var string The actual body of the review
*
* @ORM\Column(type="text", nullable=true)
* @Groups({"review:read", "book:read"})
* @ApiProperty(iri="http://schema.org/reviewBody")
*/
public $body;
If you remove the book:read group, then the generated swagger type showed above is turned into:
{
//...
"reviews": ["string"]
}
Which does not make any sense. I have removed here an annotation related to the normalizationContext and it changes the types which are related to the denormalization_context. This change should not have impacted the expected type on POST.
Possible Solution
Generated types should be an union type of string (to allow the user to passe an IRI) and the body matching the denormalization configuration. In the case of the demo, the change shown above should not have impacted the JSON types.
Additional Context
Before the change (good but should be an union):

After the change (string only despite allowing creating the relation directly):

API Platform version(s) affected: 2.5.1
Description
When allowing to create relations using
denormalization_context, the generated Swagger documentation is a list of strings instead of an union of strings and objects.How to reproduce
It's easy to reproduce the issue on the demo. We have by default the following types (which are already wrong) on the Book entity:
{ //... "reviews": [ { "body": "string", "rating": 0, "author": "string", "publicationDate": "2020-03-02T10:31:24.895Z" } ] }but the expected types should be an array of unions (
oneOf) of the above type with strings (in the case IRIs are passed).Now, for the most annoying bug:
In Review, we have the following annotations on
body:If you remove the
book:readgroup, then the generated swagger type showed above is turned into:{ //... "reviews": ["string"] }Which does not make any sense. I have removed here an annotation related to the
normalizationContextand it changes the types which are related to thedenormalization_context. This change should not have impacted the expected type on POST.Possible Solution
Generated types should be an union type of
string(to allow the user to passe an IRI) and the body matching the denormalization configuration. In the case of the demo, the change shown above should not have impacted the JSON types.Additional Context

Before the change (good but should be an union):
After the change (string only despite allowing creating the relation directly):
