使用方式:
$ gf swagger -h USAGE gf swagger [OPTION] OPTION -s, --server start a swagger server at specified address after swagger files produced -o, --output the output directory for storage parsed swagger files, the default output directory is "./swagger" -/--pack auto parses and packs swagger into packed/swagger.go. EXAMPLES gf swagger gf swagger --pack gf swagger -s 8080 gf swagger -s 127.0.0.1:8080 gf swagger -o ./document/swagger DESCRIPTION The "swagger" command parses the current project and produces swagger API description files, which can be used in swagger API server. If used with "-s/--server" option, it watches the changes of go files of current project and reproduces the swagger files, which is quite convenient for local API development. If it fails in command "swag", please firstly check your system PATH whether containing go binary path, or you can install the "swag" tool manually referring to: https://github.com/swaggo/swag
该命令内部使用的是swag
工具,相关语法请参考:https://github.com/swaggo/swag
此外,推荐使用gf
框架的swagger
插件,仓库地址:https://github.com/gogf/swagger
使用示例:
$ gf swagger --pack 2020-12-31 00:42:10.345 producing swagger files... 2020-12-31 00:42:10.452 done! 2020-12-31 00:42:10.452 gf pack swagger packed/swagger.go -n packed path 'packed/swagger.go' is not empty, files might be overwrote, continue? [y/n]: y 2020-12-31 00:42:13.954 done!
7 Comments
Yufan Sheng
Go 1.16 马上发布,Swagger 能否以 Embedded 的形式引入?
郭强
原本
gf
的swagger
就可以以资源文件的形式打包到执行文件中,Go
的Embedded
新特性也类似于它。gf
的这个特性比Go
官方实现得更早,更成熟,功能更丰富。黄昌淮
gf swagger 生成报错
fedora下:
[huang@fedora src]$ gf swagger --pack
2021-06-25 06:38:51.452 producing swagger files...
2021-06-25 06:38:54.278 /bin/bash:行1: swag:未找到命令
exit status 127
已经 go get github.com/swaggo/swag 和 go get -u github.com/swaggo/swag/cmd/swag 了
python的fastapi框架自动生成的swagger太香了,哈哈
郭强
如错误提示,没找到
swag
命令,你尝试go install
github.com/swaggo/swag/cmd/swag
试试lion
centos 系统 报这个错,请问 怎么修复呢?
[xxx@www xxx]$ go get -u github.com/gogf/swagger
go: warning: github.com/gomodule/redigo@v2.0.0+incompatible: retracted by module author: Old development version not maintained or published.
go: to switch to the latest unretracted version, run:
go get github.com/gomodule/redigo@latest
# github.com/gogf/gf/net/ghttp/internal/client
/gopath/pkg/mod/github.com/gogf/gf@v1.16.6/net/ghttp/internal/client/client_tracing.go:73:3: undefined: attribute.Any
/gopath/pkg/mod/github.com/gogf/gf@v1.16.6/net/ghttp/internal/client/client_tracing_tracer.go:150:3: undefined: attribute.Any
/gopath/pkg/mod/github.com/gogf/gf@v1.16.6/net/ghttp/internal/client/client_tracing_tracer.go:151:3: undefined: attribute.Any
[xxx@www xxx]$ go get github.com/gomodule/redigo@latest
[xxx@www xxx]$ go get -u github.com/gogf/swagger
go: warning: github.com/gomodule/redigo@v2.0.0+incompatible: retracted by module author: Old development version not maintained or published.
go: to switch to the latest unretracted version, run:
go get github.com/gomodule/redigo@latest
# github.com/gogf/gf/net/ghttp/internal/client
/gopath/pkg/mod/github.com/gogf/gf@v1.16.6/net/ghttp/internal/client/client_tracing.go:73:3: undefined: attribute.Any
/gopath/pkg/mod/github.com/gogf/gf@v1.16.6/net/ghttp/internal/client/client_tracing_tracer.go:150:3: undefined: attribute.Any
/gopath/pkg/mod/github.com/gogf/gf@v1.16.6/net/ghttp/internal/client/client_tracing_tracer.go:151:3: undefined: attribute.Any
wangxiaojie
swag 安装:go install github.com/swaggo/swag/cmd/swag@latest
wangxin
为啥gf swagger 提示找不到
PS D:\goproject\src\github.com\gogf\gf-demo-user> gf version
GoFrame CLI Tool v2.2.5, https://goframe.org
GoFrame Version: v1.16.9 // indirect in current go.mod
CLI Installed At: D:\Program Files (x86)\VMware\VMware Workstation\bin\gf.exe
CLI Built Detail:
Go Version: go1.17.13
GF Version: v2.2.5
Git Commit: 2022-11-25 10:45:56 4553f90a834ea32ff844303da3f6f18c9f091635
Build Time: 2022-11-28 20:31:52
PS D:\goproject\src\github.com\gogf\gf-demo-user> swag -v
swag.exe version v1.8.9
PS D:\goproject\src\github.com\gogf\gf-demo-user> gf swagger --pack
2022-12-26 15:56:01.951 [FATA] {ac0c7382c2483417906ca5620e4d73f6} ERROR: command "swagger" not found for command "gf", command line: D:\Program Files (x86)\VMware\VMware Workstation\bin\gf.exe swagger --pack
USAGE