Search code examples
symfonyapi-docnelmioapidocbundle

Return entity without database Nelmio Symfony


I use Nelmio to generate automatically my api doc. I would like to return an object in responseMap which is a simple class (entity without a database associated) like this :

/**
* @ApiDoc(
*  description = "Get informations from user.",
*   responseMap = {
*     200 = { "\AppBundle\Entity\MyUserInfos" },
*   },
* )
*
* @Rest\View(statusCode=Response::HTTP_OK)
* @Rest\Get("/my_user_infos")
*/ 
public function getMyUserInfosAction(Request $request) {
...
}


namespace AppBundle\Entity;

/**
 * MyUserInfos
 */
class MyUserInfos
{
 /**
 * @var string
 */
private $username;

/**
 * @var string
 */
private $email;

+getters and setters
}

But response object is not displayed in my api doc. Can anyone help me ? Thanks.


Solution

  • Remove the leading backslash on you class name

    /**
    * @ApiDoc(
    *  description = "Get informations from user.",
    *   responseMap = {
    *     200 = { "AppBundle\Entity\MyUserInfos" },
    *   },
    * )
    *
    * @Rest\View(statusCode=Response::HTTP_OK)
    * @Rest\Get("/my_user_infos")
    */ 
    public function getMyUserInfosAction(Request $request) {
    ...
    }
    

    See:https://github.com/nelmio/NelmioApiDocBundle/blob/2d70b0802144fd2c868783c46fa1be4a774967d4/Resources/doc/swagger-support.rst#multiple-response-models