Skip to content

@Assert\NotNull annotation always added for attributes with custom name #134

@JulienCheny

Description

@JulienCheny

On the last api-platform distribution.

Actual Result

When I generate entity with an attribute that is not in schema.org, @Assert\NotNull annotation is always added.

Expected Result

@Assert\NotNull should be added only when I write nullable: false.

Example

/api-platform/api/config/schema.yml

types:
    Thing:
        parent: false 
        properties:
            name: ~
            customName: {range: Text}
            otherCustomName: {range: Text, nullable: true, ormColumn: 'type="text", nullable=true'}

/api-platform/api/src/Entity/Thing.php

class Thing
{
[...]
    /**
     * @var string|null the name of the item
     *
     * @ORM\Column(type="text", nullable=true)
     * @ApiProperty(iri="http://schema.org/name")
     */
    private $name;

    /**
     * @var string
     *
     * @ORM\Column(type="text")
     * @Assert\NotNull
     */
    private $customName;

    /**
     * @var string
     *
     * @ORM\Column(type="text", nullable=true)
     * @Assert\NotNull
     */
    private $otherCustomName;
[...]

For a standard attribute, the @Assert\NotNull annotation is not added.
but that's the case for all other custom entities.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions