[Feature]: PHPDoc with union of constant strings could/should be considered an enum
RobertMe opened this issue · 1 comments
Description
Hi,
I have some code like this:
/**
* @var 'one'|'two'|'three'
*/
public string $prop;
In the OpenAPI JSON this however is rendered into:
"prop": {
"oneOf": [
{
"type": "string"
},
{
"type": "string"
},
{
"type": "string"
}
]
},
Which obviously is kinda wrong because of the oneOf
which contains the same value ({"type": "string"}
) multiple times.
Furthermore it would be nice if this union would automatically be converted into an enum, resulting in:
"prop": {
"type": "string",
"enum": [
"one",
"two",
"three"
]
}
Additional context
No response
In addition to this. When setting an enum as well (either using #[Property(enum: ['one', 'two', 'three'])
or using Symfony-s Choice
constraint) this "breaks" Swagger UI as well, as it just shows the oneOf
and not the enum
. When then removing this PHPDoc it does properly show the possible enum values. Which in turn also makes me wonder whether it would actually be valid to have a combination of enum
and oneOf
(as I can imagine that the enum cases all must be of the same type).