Open
Description
Version
4.3.0
Description
When setting a #[Property] changing the type of the property, nullable is ignored and the result json makes the property nullable:
This is my code:
class UserStyleDto extends AbstractDto
{
private StyleDto $style;
#[Property(ref: new Model(type: CodeCaptionDto::class), nullable: false)]
private StyleLevelEnum $level;
public function __construct(UserStyle $userStyle)
{
$this->style = new StyleDto($userStyle->getStyle());
$this->level = $userStyle->getLevel();
}
public function getStyle(): StyleDto
{
return $this->style;
}
public function getLevel(): StyleLevelEnum
{
return $this->level;
}
}
To make $level not nullable, I have to add #[Assert\NotNull].
If I don't use the #[Property] then the $level is not nullabel correctly.
I have a Normalizer that normalizes the StyleLevelEnum to a CodeCaptionDto.
JSON OpenApi
JSON OpenApi
"UserStyleDto": {
"required": [
"style"
],
"properties": {
"style": {
"$ref": "#/components/schemas/StyleDto"
},
"level": {
"$ref": "#/components/schemas/CodeCaptionDto"
}
},
"type": "object"
},
Additional context
May be related with this issue: #2111