【问题标题】:NelmioApiDocBundle doesn't work "No operations defined in spec!"NelmioApiDocBundle 不起作用“规范中没有定义操作!”
【发布时间】:2019-02-10 07:11:33
【问题描述】:

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

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

我也尝试了https://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html上的示例

怎么了?有什么想法吗?

routing.yml

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

config.yml

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

控制器

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

}   

composer.json

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

【问题讨论】:

  • 我也遇到了同样的问题,你解决了吗?

标签: symfony symfony-3.4 nelmioapidocbundle


【解决方案1】:

只需删除

host_patterns:
    - ^api\.

并在

中设置您的虚拟主机
documentation:
  host: symfony.localhost

【讨论】:

  • 非常感谢!!
【解决方案2】:

问题在于 config.yml 路径模式。如果您删除配置(所有 nelmio_api_doc)或更改路径模式将起作用。示例:

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

【讨论】:

  • "nelmio/api-doc-bundle": "^3.6@dev" Unrecognized option "default" under "nelmio_api_doc.areas.default". Available options are "documentation", "host_patterns", "name_patterns", "path_patterns", "with_annotation".
【解决方案3】:

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

php bin/console assets:install --symlink

【讨论】:

    猜你喜欢
    • 2020-10-01
    • 1970-01-01
    • 2022-11-01
    • 2023-03-08
    • 1970-01-01
    • 2019-06-07
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    相关资源
    最近更新 更多