【问题标题】:Why does a custom route appears twice in Nelmio API Doc?为什么自定义路由在 Nelmio API Doc 中出现两次?
【发布时间】:2017-04-29 11:02:00
【问题描述】:

我尝试为我的一个 API 定义自定义路由名称,从那时起,API Doc 显示该路由两次。任何想法为什么?

这是我的 API 的定义:

/**
 * @ApiDoc(
 *   description = "Sends the support email to the HelpDesk address",
 *   statusCodes = {
 *     204 = "Returned when successful",
 *     400 = "Returned when the parameters are incorrect",
 *     401 = "Returned when the token is invalid",
 *     500 = "Returned when there's an internal server error"
 *   },
 *   input="AppBundle\Form\Type\SupportEmailType"
 * )
 * @Post("/support-requests")
 * @Rest\View ()
 */
public function postSupportAction(Request $request)

以下是路线在我的文档中的显示方式:

这是我的routing.yml 文件:

# app/config/routing.yml
app:
    resource: "@AppBundle/Controller/"
    type:     annotation
NelmioApiDocBundle:
   resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
   prefix:   /api/doc
user:
    type:     rest
    resource: AppBundle\Controller\UserController

【问题讨论】:

  • 你能把 routing.yml 的设置也贴出来吗?
  • @AlexandruCosoi 我已经用我的 routing.yml 文件的内容更新了问题
  • 我不记得我上次使用 FOSRestBundle 是什么时候了,但我要废话一句,根据这个问题,你在某处定义了两次路由:github.com/FriendsOfSymfony/FOSRestBundle/issues/813
  • @Sebastian @Post("/support-requests") 的命名空间是什么?
  • @AlexandruCosoi 这是 Symfony 网站上提到的那个:symfony.com/doc/current/bundles/FOSRestBundle/…,看起来像这样use FOS\RestBundle\Controller\Annotations\Post;

标签: symfony fosrestbundle nelmioapidocbundle


【解决方案1】:

从表面上看,唯一能想到的可能是你的 routing.yml 的第一部分

尝试从您的 routing.yml 中删除它

app:
    resource: "@AppBundle/Controller/"
    type:     annotation

我认为这段代码,以及用户路由的分离定义让 nelmio 看到了两次路由。前段时间我遇到了类似的问题,我认为这就是原因。很抱歉我不得不问这么多问题,但我需要看到完整的画面。

希望对你有帮助,

亚历山德鲁·科索伊

【讨论】:

  • 成功了! :D 一个 mers!
  • 铜 :) 。玩得开心
猜你喜欢
  • 2018-03-17
  • 2018-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-25
  • 2013-10-22
相关资源
最近更新 更多