NelmioApiDocBundle 无法"No operations defined in spec!"工作



我想将nelmio用于symfony-project,但它不起作用。

它总是说:规范中没有定义任何操作!

我也尝试了这个例子 https://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html

怎么了?有什么想法吗?

路由.yml

app.swagger_ui:
path: /api/doc
methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger_ui }

配置.yml

nelmio_api_doc:
areas:
path_patterns: # an array of regexps
- ^/api(?!/doc$)
host_patterns:
- ^api.

控制器

/**
* @Route("/api/test", methods={"GET"})
* @SWGResponse(
*     response=200,
*     description="Returns the rewards of an user"
* )
* @SWGParameter(
*     name="order",
*     in="query",
*     type="string",
*     description="The field used to order rewards"
* )
*/
public function testAction()
{
}   

作曲家.json

"symfony/symfony": "3.4.*",
"nelmio/api-doc-bundle": "3.2.1",

只需删除

host_patterns:
- ^api.

并将虚拟主机设置为

documentation:
host: symfony.localhost

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

PHP bin/console 资源:安装 --符号链接

问题出在 config.yml 路径模式中。如果您删除配置(全部nelmio_api_doc(或更改路径模式将起作用。例:

nelmio_api_doc:
areas:
default:
path_patterns: [ /api/ ]

最新更新