bee
bee copied to clipboard
Router parsing nonsupport multi namespace in swagger(路由注解不支持多个namespace在swagger中)
nsv1 := beego.NewNamespace("/v1",
beego.NSNamespace("/user",
beego.NSInclude(
&c_v1.UserController{},
),
)
nsv2 := beego.NewNamespace("/v2",
beego.NSNamespace("/user",
beego.NSInclude(
&c_v2.UserController{},
),
)
beego.AddNamespace(nsv1, nsv2)
===========english=========== I encountered problems. In bee 1.9.1, the URL address of swagger's request address /v2/user/xxx was changed to /v1/v2/user/xxx, resulting in not found. I found the source code
1, we first discover the "basePath:/v1" in swagger.json. 2, secondly, the first parameter in NewNamespace in bee is "/v1". 3. Source code https://github.com/beego/bee/generate/swaggergen/g_docs.go
version, params := analyseNewNamespace(v)
if rootapi.BasePath == "" && version != "" {
rootapi.BasePath = version
}
I think the core problem is swagger.json in namespace, or many swagger.json, I look at the official meaning of swagger, it should be more swagger.json to deal with. http://petstore.swagger.io/v2/swagger.json ---------------------------^---------------
I hope directory structure as follows. /swagger/namespace/v1/swagger.json (default) /swagger/namespace/v2/swagger.json
===========中文=========== 我遇到问题,在bee1.9.1的里面swagger中的请求地址/v2/user/xxx 的url地址被换成了 /v1/v2/user/xxx,导致not found。我找了下源码
1、首先发现swagger.json中的"basePath:/v1"。 2、其次bee中的NewNamespace中的第一个参数为"/v1"。 3、源码https://github.com/beego/bee/generate/swaggergen/g_docs.go
version, params := analyseNewNamespace(v)
if rootapi.BasePath == "" && version != "" {
rootapi.BasePath = version
}
我想核心问题还是swagger.json中分namespace,还是多个swagger.json问题,我看swagger官方的意思,应该是多个swagger.json来处理。 http://petstore.swagger.io/v2/swagger.json ---------------------------^---------------
我希望目录结构如下: /swagger/namespace/v1/swagger.json (default) /swagger/namespace/v2/swagger.json
add @BasePath in router.go
这个问题解决了吗?
可以看看 #866 https://github.com/beego/bee/pull/866