Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat multi namespace gen swagger #866

Merged
merged 2 commits into from
Apr 10, 2024

Conversation

lenmx
Copy link
Contributor

@lenmx lenmx commented Apr 8, 2024

增加了多命名空间情况下的 swager 生成
在生成 swagger.json 时也同时修改 swagger/index.html,使其动态根据多命名空间引入多个 swagger.json 文件
生成的 swagger.json 文件路径:swagger/{namespace}/swagger.json

如何使用:
1、修改 router.go 文档定义

// @NamespacePrefix /api/v1
// @APIVersion 1.0.0
// @Title API v1
// @Description API v1 description
// @Schemes http
func initAPIV1() {
	webapi := beego.NewNamespace("/api/v1",
		beego.NSNamespace("/user", beego.NSInclude(&test_api_v1.SysUserController{})),
	)
	beego.AddNamespace(webapi)
}

// @NamespacePrefix /api/v2
// @APIVersion 2.0.0
// @Title API v1
// @Description API v2 description
// @Schemes http
func initAPIV2() {
	webapi := beego.NewNamespace("/api/v2",
		beego.NSNamespace("/user", beego.NSInclude(&test_api_v2.SysUserController{})),
	)
	beego.AddNamespace(webapi)
}

2、执行 bee run -gendoc=true -downdoc=true
3、打开swagger地址,你将看到你想要的结果

demo地址: https://github.com/lenmx/beego_multi_version_swagger_demo

screenshot

@flycash
Copy link
Collaborator

flycash commented Apr 9, 2024

等我验证一下

@flycash flycash merged commit a1ef20e into beego:develop Apr 10, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants