Swagger 生成忽略了 SecurityDefinton

问题描述

无法理解一件事,为什么 swag init 命令会生成所有内容,除了 SecurityDeFinition

例如,这是我在主函数上的代码

// @title Swagger API
// @version 1.0
// @description This is a documentation for PlatOps Core tool.
// @termsOfService http://platops.com/
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host test.com
// @BasePath /v2
// @securityDeFinitions.apikey Bearer
// @in header
// @name Authorization

以及我的使用方式:

// GetUser godoc
// @Summary Retrieves users list
// @Tags users
// @Accept json
// @Produce json
// @Success 200 {object} string
// @Failure 400,404 {object} string
// @Failure 500 {object} string
// @Router /api/users/ [get]
// @Security Bearer

由此,它生成了一切,这条路径也是,但里面没有 SecurityDeFinition 块。

我正在尝试实现这一点: https://github.com/swaggo/swag#security

附言如果我将已经生成的文本放在生成的 doc 文件中,它就可以工作……那为什么它不能生成它?

"securityDeFinitions": {
        "api_key": {
            "type": "apiKey","name": "Bearer","in": "header"
        },}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)