方法来源:https://www.jianshu.com/p/1837b37e03f8
go-admin 框架配置了swagger的,但是当我修改了内容,添加了自己的借口之后,想生成新的swagger文档,却报错了:
ParseComment error in file xxx :cannot find type definition: response.Response
然后看到接口上的定义swagger参数:
// ServerInfo 获取系统信息
// @Summary 系统信息
// @Description 获取JSON
// @Tags 系统信息
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/server-monitor [get]
// @Security Bearer
这里的
@Success 200 {object} response.Response “{“code”: 200, “data”: […]}”
response.Response是外部依赖:“github.com/go-admin-team/go-admin-core/sdk/pkg/response”
在项目中,我看到已经引入该依赖:
import (
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
)
因为并未实际应用了该依赖,所以要用横杆注释掉,但是它初始化了,就足够了。
查资料发现,原来还要加参数,才能识别到外部依赖:
swag init --parseDependency --parseInternal
PS :后面才发现,原来go-admin人家准备好了,在main.go中:
vs code 有插件的话,直接点”run go generate“即可