没有数据库的返回实体Nelmio Symfony

时间:2017-02-15 19:47:30

标签: symfony api-doc nelmioapidocbundle

我使用Nelmio自动生成我的api doc。我想在responseMap中返回一个对象,它是一个简单的类(没有数据库关联的实体),如下所示:

/**
* @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
}

但是我的api doc中没有显示响应对象。谁能帮我 ? 感谢。

1 个答案:

答案 0 :(得分:0)

删除班级名称上的反斜杠

/**
* @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) {
...
}

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