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

Properties with default values are required #2179

Closed
xabbuh opened this issue Jan 5, 2024 · 2 comments · Fixed by #2186
Closed

Properties with default values are required #2179

xabbuh opened this issue Jan 5, 2024 · 2 comments · Fixed by #2186

Comments

@xabbuh
Copy link

xabbuh commented Jan 5, 2024

namespace App;

use OpenApi\Annotations as OA;
use Symfony\Component\Validator\Constraints as Assert;

class FooBar
{
    /**
     * @OA\Property( default="emtpy string ('')",
     *     description="text that should be displayed in monitoring for the status code (when it will be detected as error)")
     * @Assert\Type(type="string")
     */
    private string $foo = '';

    /**
     * @Assert\Valid()
     *
     * @var string[]
     */
    private array $bar;

    public function __construct()
    {
        $this->bar = [];
    }
}

Before #2141 with a class definition like above the properties $foo and $bar where not marked as required. Now they are.

@DjordyKoert
Copy link
Collaborator

The $foo should indeed not be required. But I am not sure how we should handle/detect the $bar value.

@heiglandreas
Copy link
Contributor

It looks like all cases of "falsy" defaults are now ignored and the properties are then marked as required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants