【问题标题】:NelmioApiDocBundle not generate documentationNelmioApiDocBundle 不生成文档
【发布时间】:2018-11-11 16:23:48
【问题描述】:

我想使用 NelmioApiDocBundle 自动生成文档。我使用标准 Symfony 文档来安装和配置它:https://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html。不幸的是,当我转到 /api/doc 时,我的文档是空的。

我在 v. 3.2.0 中使用 Symfony 3.4 和 NelmioApiDocBundle。

这是我的配置:

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

【问题讨论】:

  • 你有什么解决办法吗?我面临着类似的问题。
  • 我没有时间解决这个问题。我刚开始使用 Sami。
  • 你没有指定方法。

标签: php symfony nelmioapidocbundle


【解决方案1】:

试试这个:

替换

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

 @Rest\Get("/getVehicles")

并且,在你的动作控制器中,像这样返回数组或对象:

    $em = $this->getDoctrine();
    return $em->getRepository('AppBundle:Vehicle')->findAll();

【讨论】:

  • 所以,此时我创建了简单的 CRUD 应用程序。是否可以使用 NelmioApiDocBundle 为 CRUD 生成文档?
  • 我认为不可能,但我从不尝试这个
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

    如果任何命令事件(通常是post-install-cmdpost-update-cmd)触发ScriptHandler::installAssets 脚本,则资产通常由作曲家安装。如果你还没有设置这个脚本,你可以手动执行这个命令:

    php bin/console assets:install --symlink
    

    【讨论】:

      猜你喜欢
      • 2020-06-03
      • 2015-11-27
      • 1970-01-01
      • 2020-08-15
      • 2015-02-22
      • 1970-01-01
      • 2021-04-05
      • 1970-01-01
      • 2014-01-17
      相关资源
      最近更新 更多