Skip to content

@Assert\NotNull annotation automatically added in all fields #107

@Simperfit

Description

@Simperfit

Taken from api-platform/api-platform#363

Actual Result

When generate entity file using schema.yml file, @Assert\NotNull annotation automatically added.

Expected Result

@Assert\NotNull should not add in entity file

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

    Users:                       
        parent: false
        properties:
            createdAt: { range: "DateTime" }
            updatedAt: { range: "DateTime" } 
            username: { range: "Text", ormColumn: 'type="string", length=255' }
            email: { range: "Text", ormColumn: 'type="string", length=255' }
            password: { range: "Text", ormColumn: 'type="string", length=255' }

Entity generate using command:

php vendor/bin/schema generate-types src/ app/config/schema.yml

/api-platform/src/AppBundle/Entity/Users.php

<?php

namespace AppBundle\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * The most generic type of item.
 *
 * @see http://schema.org/Thing Documentation on Schema.org
 *
 * @ORM\Entity
 * @ApiResource(iri="http://schema.org/Thing")
 */
class Users
{
    /**
     * @var int
     *
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime")
     * @Assert\DateTime
     * @Assert\NotNull
     */
    private $createdAt;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime")
     * @Assert\DateTime
     * @Assert\NotNull
     */
    private $updatedAt;

    /**
     * @var string
     *
     * @ORM\Column(type="string", length=255)
     * @Assert\Type(type="string")
     * @Assert\NotNull
     */
    private $username;

    /**
     * @var string
     *
     * @ORM\Column(type="string", length=255)
     * @Assert\Type(type="string")
     * @Assert\NotNull
     */
    private $email;

    /**
     * @var string
     *
     * @ORM\Column(type="string", length=255)
     * @Assert\Type(type="string")
     * @Assert\NotNull
     */
    private $password;
    ....
    ....
    ....
}

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