api-platform icon indicating copy to clipboard operation
api-platform copied to clipboard

Swagger UI ignores required property based on code case convention

Open Kallys opened this issue 3 years ago • 0 comments

API Platform version(s) affected: 2.6.8

Description
Swagger UI ignores required property when mixing snake_case for variables and camelCase for accessors in entities.

How to reproduce

#[ApiResource(...)]
#[ORM\Entity]
class AnEntity
{
    #[ORM\OneToOne(...)]
    #[Assert\NotNull]
    private AnotherEntity $another_entity;

    /**
     * @return AnotherEntity
     */
    public function getAnotherEntity(): AnotherEntity
    {
        return $this->another_entity;
    }

    /**
     * @param AnotherEntity $another_entity
     */
    public function setAnotherEntity(AnotherEntity $another_entity): void
    {
        $this->another_entity= $another_entity;
    }
}

Possible Solution

  1. Clearly expose in documentation that Symfony naming convention is required
  2. Make metadata loaders aware of project naming convention
  3. The third solution

Additional Context

Kallys avatar May 03 '22 13:05 Kallys