Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Setting property not nullable results in a nullable property #2340

Open
davidrojo opened this issue Sep 20, 2024 · 0 comments
Open

[Bug]: Setting property not nullable results in a nullable property #2340

davidrojo opened this issue Sep 20, 2024 · 0 comments
Labels

Comments

@davidrojo
Copy link

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

@davidrojo davidrojo added the bug label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant