0

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.

cezar
  • 11,616
  • 6
  • 48
  • 84
Ced M
  • 13
  • 4

1 Answers1

0

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

flxPeters
  • 1,476
  • 12
  • 21
  • Thanks for your answer. Unfortunately it does not work better. I tried with or without bracket but no changes. Is it possible to use an entity without ORM link ? – Ced M Feb 16 '17 at 07:52
  • You definitely don't need any ORM here. Can you see the response map in your ApiDoc and the proporties are empty? If you don't use the ORM you may have to add the Serializer annotations. – flxPeters Feb 16 '17 at 08:33
  • I see the response map ("Return" section with code 200 inside) but properties are empty. I have serializer annotation enabled (default serializer). But no success. – Ced M Feb 16 '17 at 10:51
  • Does you MyUserInfos proporties gave the annotations? The bundle must have informations like ORM or Serializer annotations to know which proporties are available. – flxPeters Feb 16 '17 at 12:04
  • Ok. So i had annotations like @Type("string") in all properties, then enabled JMS serializer, and now MyUserInfos properties are displayed in api doc. That was what you were thinking ? – Ced M Feb 16 '17 at 15:02
  • Yes, my problem is solved. Thanks a lot for your help. – Ced M Feb 16 '17 at 19:33