mirror of
https://github.com/xxjwxc/ginrpc.git
synced 2025-09-26 19:21:18 +08:00
add doc option case
添加文档输出选型
This commit is contained in:
@@ -160,6 +160,8 @@ func main() {
|
||||
ginrpc.WithCtx : Set custom context
|
||||
|
||||
ginrpc.WithDebug(true) : Set debug mode
|
||||
|
||||
ginrpc.WithOutDoc(true) : output markdown/swagger api doc
|
||||
|
||||
ginrpc.WithBigCamel(true) : Set big camel standard (false is web mode, _, lowercase)
|
||||
|
||||
@@ -179,6 +181,10 @@ func main() {
|
||||
|
||||
## 二. swagger/markdown/mindoc Document generation description
|
||||
|
||||
```
|
||||
ginrpc.WithOutDoc(true) : output markdown/swagger
|
||||
```
|
||||
|
||||
### 1.For object registration 'ginrpc. Register' mode, document export is supported
|
||||
### 2.Export supports annotation routing, Parameter annotation and default value (` tag '. ` default')
|
||||
### 3.Default export path:(`/docs/swagger/swagger.json`,`/docs/markdown`)
|
||||
|
@@ -158,6 +158,8 @@ _ "[mod]/routers" // debug模式需要添加[mod]/routers 注册注解路由
|
||||
|
||||
ginrpc.WithDebug(true) : 设置debug模式
|
||||
|
||||
ginrpc.WithOutDoc(true) : 设置输出 markdown/swagger 接口文档
|
||||
|
||||
ginrpc.WithBigCamel(true) : 设置大驼峰标准(false 为web模式,_,小写)
|
||||
|
||||
ginrpc.WithBeforeAfter(&ginrpc.DefaultGinBeforeAfter{}) : 设置调用前后执行中间件
|
||||
@@ -170,6 +172,11 @@ _ "[mod]/routers" // debug模式需要添加[mod]/routers 注册注解路由
|
||||
|
||||
## 二. swagger/markdown/mindoc 文档生成说明
|
||||
|
||||
|
||||
```
|
||||
ginrpc.WithOutDoc(true) : 设置输出 markdown/swagger 接口文档
|
||||
```
|
||||
|
||||
### 1.对于对象注册`ginrpc.Register`模式,支持文档导出
|
||||
### 2.导出支持注解路由,支持参数注释,支持默认值(`tag`.`default`)
|
||||
### 3.默认导出路径:(`/docs/swagger/swagger.json`,`/docs/markdown`)
|
||||
|
15
common.go
15
common.go
@@ -462,9 +462,14 @@ func (b *_Base) tryGenRegister(router gin.IRouter, cList ...interface{}) bool {
|
||||
if _b {
|
||||
if sdl, ok := funMp[method.Name]; ok {
|
||||
gcs, req, resp := b.parserComments(sdl, objName, method.Name, imports, objPkg, num)
|
||||
docReq, docResp := b.parserStruct(req, resp, astPkgs, modPkg, modFile)
|
||||
if b.isOutDoc { // output doc
|
||||
docReq, docResp := b.parserStruct(req, resp, astPkgs, modPkg, modFile)
|
||||
for _, gc := range gcs {
|
||||
doc.AddOne(objName, gc.RouterPath, gc.Methods, gc.Note, docReq, docResp)
|
||||
}
|
||||
}
|
||||
|
||||
for _, gc := range gcs {
|
||||
doc.AddOne(objName, gc.RouterPath, gc.Methods, gc.Note, docReq, docResp)
|
||||
checkOnceAdd(objName+"."+method.Name, gc.RouterPath, gc.Methods)
|
||||
}
|
||||
}
|
||||
@@ -473,8 +478,10 @@ func (b *_Base) tryGenRegister(router gin.IRouter, cList ...interface{}) bool {
|
||||
}
|
||||
}
|
||||
|
||||
doc.GenSwagger(modFile + "/docs/swagger/")
|
||||
doc.GenMarkdown(modFile + "/docs/markdown/")
|
||||
if b.isOutDoc {
|
||||
doc.GenSwagger(modFile + "/docs/swagger/")
|
||||
doc.GenMarkdown(modFile + "/docs/markdown/")
|
||||
}
|
||||
genOutPut(b.outPath, modFile) // generate code
|
||||
return true
|
||||
}
|
||||
|
13
ginrpc.go
13
ginrpc.go
@@ -18,6 +18,7 @@ type _Base struct {
|
||||
apiType reflect.Type
|
||||
outPath string // output path.输出目录
|
||||
beforeAfter GinBeforeAfter
|
||||
isOutDoc bool
|
||||
}
|
||||
|
||||
// Option overrides behavior of Connect.
|
||||
@@ -62,6 +63,13 @@ func WithBigCamel(b bool) Option {
|
||||
})
|
||||
}
|
||||
|
||||
// WithOutDoc set is out doc.是否输出文档
|
||||
func WithOutDoc(b bool) Option {
|
||||
return optionFunc(func(o *_Base) {
|
||||
o.isOutDoc = b
|
||||
})
|
||||
}
|
||||
|
||||
// WithBeforeAfter set before and after call.设置对象调用前后执行中间件
|
||||
func WithBeforeAfter(beforeAfter GinBeforeAfter) Option {
|
||||
return optionFunc(func(o *_Base) {
|
||||
@@ -94,6 +102,11 @@ func (b *_Base) Dev(isDev bool) {
|
||||
b.isDev = isDev
|
||||
}
|
||||
|
||||
// OutDoc set if out doc. 设置是否输出接口文档
|
||||
func (b *_Base) OutDoc(isOutDoc bool) {
|
||||
b.isOutDoc = isOutDoc
|
||||
}
|
||||
|
||||
// Model use custom context
|
||||
func (b *_Base) Model(middleware NewAPIFunc) *_Base {
|
||||
if middleware == nil { // default middleware
|
||||
|
2
go.mod
2
go.mod
@@ -5,7 +5,7 @@ go 1.12
|
||||
require (
|
||||
github.com/gin-gonic/gin v1.6.3
|
||||
github.com/go-playground/validator/v10 v10.2.0
|
||||
github.com/xxjwxc/public v0.0.0-20200806165443-643811bf4a0e
|
||||
github.com/xxjwxc/public v0.0.0-20200806170246-c98b0706a117
|
||||
)
|
||||
|
||||
// replace github.com/xxjwxc/public => ../public
|
||||
|
9
go.sum
9
go.sum
@@ -169,14 +169,9 @@ github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLY
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||
github.com/xxjwxc/gowp v0.0.0-20200603130651-4d7368b0e285/go.mod h1:yJ/fY5BorWARfDDsxBU/MyQTHc5MVyNcqBQQYD6MN0k=
|
||||
github.com/xxjwxc/public v0.0.0-20200603115833-341beff27850 h1:UCW8LJHTCOlkQt1+KUovAX1T7jAaUZch95yrIfKfZuU=
|
||||
github.com/xxjwxc/public v0.0.0-20200603115833-341beff27850/go.mod h1:fp3M+FEQrCgWD1fZ/PLwZkCTglf086OEhC9LcydAUnc=
|
||||
github.com/xxjwxc/public v0.0.0-20200624081057-e7dc0aa6e887 h1:zgSB9vgUwYklK7O+Jms1wsb0XrobRF6Krg6cqSnKDF4=
|
||||
github.com/xxjwxc/public v0.0.0-20200624081057-e7dc0aa6e887/go.mod h1:0BFWVHqt7nKW8MtIx7R7bOkoGQFFnKsaJeeVbkzY88E=
|
||||
github.com/xxjwxc/public v0.0.0-20200710160137-ccf3e4f07a03 h1:jd3Eq8PGmwrmlrhMPpmqfGyiC2qFVBRA38n3HFFv9+Y=
|
||||
github.com/xxjwxc/public v0.0.0-20200710160137-ccf3e4f07a03/go.mod h1:0BFWVHqt7nKW8MtIx7R7bOkoGQFFnKsaJeeVbkzY88E=
|
||||
github.com/xxjwxc/public v0.0.0-20200806165443-643811bf4a0e h1:q4/pr6g9tak3UiL3q43YIRxSTk4oVrBebYbkFIZegPY=
|
||||
github.com/xxjwxc/public v0.0.0-20200806165443-643811bf4a0e/go.mod h1:0BFWVHqt7nKW8MtIx7R7bOkoGQFFnKsaJeeVbkzY88E=
|
||||
github.com/xxjwxc/public v0.0.0-20200806170246-c98b0706a117 h1:b0n+CBXKl6rxu+v6v2kwVhBn2sJgnugzaTJ/FIPY/dw=
|
||||
github.com/xxjwxc/public v0.0.0-20200806170246-c98b0706a117/go.mod h1:0BFWVHqt7nKW8MtIx7R7bOkoGQFFnKsaJeeVbkzY88E=
|
||||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
|
Reference in New Issue
Block a user