NelmioApiDocBundle 无法生成文档

3
我希望使用 NelmioApiDocBundle 自动生成文档。我按照 Symfony 标准文档进行了安装和配置,链接如下:https://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html。但是当我访问 /api/doc 时,我的文档为空。
我使用的是 Symfony 3.4 和 NelmioApiDocBundle 版本为 3.2.0。
以下是我的配置信息:
nelmio_api_doc:
    areas:
        path_patterns: # an array of regexps
            - ^/api(?!/doc$)
        host_patterns:
            - ^api\.
    documentation:
        host: 127.0.0.1
        schemes: [http, https]
        info:
            title: Thanatos API
            description: This is documentation of Thanatos
            version: 1.0.0
        security:
            - Bearer: []

在我的控制器中添加注释(一开始我想在文档中看到任何数据):

/**
 * @Route(
 *  "/",
 *  name="thanatos_dashboard_index", 
 * )
 *
 * @SWG\Response(
 *     response=200,
 *     description="Returns the rewards of an user",
 *     @SWG\Schema(
 *         type="array",
 *         @SWG\Items(ref=@Model(type=Reward::class, groups={"full"}))
 *     )
 * )
 * @SWG\Parameter(
 *     name="order",
 *     in="query",
 *     type="string",
 *     description="The field used to order rewards"
 * )
 * @SWG\Tag(name="rewards")
 * @NelmioSecurity(name="Bearer")
 */
public function indexAction()
{
    return $this->render("@AppThanatos/Dashboard/index.html.twig");
}

在/api/doc页面上,我看到“规范中未定义任何操作!”。我做错了什么吗?
@更新
我刚刚开始使用Sami:http://symfony.com/projects/sami

你有什么解决方案吗?我也遇到了类似的问题。 - Sandeep Gupta
我没有时间解决这个问题。我刚开始使用Sami。 - Radosław Andraszyk
你没有指定方法。 - Bart
3个回答

0

通常情况下,如果任何命令事件(通常是post-install-cmdpost-update-cmd)触发ScriptHandler::installAssets脚本,则会由composer安装资产。如果您尚未设置此脚本,则可以手动执行此命令:

php bin/console assets:install --symlink

0

我有同样的问题。在我的 Mac 上工作时,我总是遇到 ERR_EMPTY_RESPONSE(使用 Chrome),但在生产环境中,相同的配置正常工作。

唯一的区别是 Xdebug,我尝试禁用该模块,现在一切都正常了。


-2
尝试这个:
替换

 * @Route(
 *  "/",
 *  name="thanatos_dashboard_index", 
 * )

通过

 @Rest\Get("/getVehicles")

在你的控制器中,返回像这样的数组或对象:
    $em = $this->getDoctrine();
    return $em->getRepository('AppBundle:Vehicle')->findAll();

所以,此时我正在创建一个简单的CRUD应用程序。是否可以使用NelmioApiDocBundle生成CRUD文档? - Radosław Andraszyk
我认为这是不可能的,但我从未尝试过。 - Jean francois LEFLOCH

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接