swaggeropenapiswagger-phpnelmioapidocbundle

NelmioApiDoc model definition / how to ignore getter or alias to existing property with other name?


Can we overwride model accessor property name or ignore it?

Here my User::getUsername function which is an getter for email property (I need this function named like that to implement interface):

class User extends AbstractDocument implements AdvancedUserInterface, EquatableInterface
{
    /**
     * @var string
     * @Assert\NotBlank()
     * @Assert\Email()
     * @SWG\Property(
     *     description="The email of the user",
     *     example="example@company.com"
     * )
     */
    private $email;

    //...

    /**
     * Returns the username used to authenticate the user.
     * @return string The user email
     * @SWG\Property(property="email")
     */
    public function getUsername()
    {
        return $this->email;
    }
}

And the generated doc is still showing both:

{
  "User": {
    "properties":{
      "email":{  
        "description":"The email of the user",
        "example":"example@company.com",
        "type":"string"
      },
      "username":{  
        "type":"string"
      }
    }
  }
}

Can you help me with that ?


Solution

  • NelmioApiDoc respects the Ignore attribute, so you can hide the method/field like this:

    use Symfony\Component\Serializer\Annotation\Ignore;
    
    /**
     * @Ignore
     */
    public function getUsername()
    
    // or
    
    #[Ignore]
    public function getUsername()