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

Automatically generate documents #4055

Open
HHC26 opened this issue Sep 13, 2024 · 3 comments
Open

Automatically generate documents #4055

HHC26 opened this issue Sep 13, 2024 · 3 comments

Comments

@HHC26
Copy link

HHC26 commented Sep 13, 2024

Handwriting documents can be troublesome, but existing tools require handwriting for each API, which is repetitive work
// Query
// @tags User
// @summary User
// @Security ApiKeyAuth
// @param data query dto.SysUserQuery true
// @success 200 {object} response.JsonResult{data=response.PageResult{list=[]dto.SysUserVo}}
// @router /system/user/query [get]

What are some good solutions that can be automatically generated?

@JIeJaitt
Copy link

@HHC26 Hello, can you give some examples? For my understanding?

@HHC26
Copy link
Author

HHC26 commented Sep 24, 2024

What are some good solutions that can be automatically generated?

@HHC26 Hello, can you give some examples? For my understanding?

// CreateApi
// @tags SysApi
// @summary xx_api
// @Security ApiKeyAuth
// @accept application/json
// @produce application/json
// @param data body system.SysApi true "x"
// @success 200 {object} response.Response{msg=string} "xx_api"
// @router /api/createApi [post]
func CreateApi(c *gin.Context) {
// todo
}

// SyncApi
// @tags SysApi
// @summary xx_API
// @Security ApiKeyAuth
// @accept application/json
// @produce application/json
// @success 200 {object} response.Response{msg=string} "xx_API"
// @router /api/syncApi [get]
func SyncApi(c *gin.Context) {
// todo
}

func RouterApp() *gin.Engine {
router := gin.Default()
router.GET("/syncApi", SyncApi)
router.POST("/createApi", CreateApi)
}

This is a very common expression!

@HHC26
Copy link
Author

HHC26 commented Sep 24, 2024

@HHC26 Hello, can you give some examples? For my understanding?

Gin automatically implements binding routing, parameter verification, and generating swaggers, which can reduce a lot of workload when developing the web

type UserSearchReq struct {
g.Meta path:"/user/list" tags:"sysUser" method:"get" summary:"xxx"
DeptId string p:"deptId"
RoleId uint p:"roleId"
Status string p:"status"
}
type UserSearchRes struct {
g.Meta mime:"application/json"
UserList []*model.SysUserRoleDeptRes json:"userList"
}

type UserAddReq struct {
g.Meta path:"/user/add" tags:"sysUser" method:"post" summary:"xxx"
UserName string p:"userName" v:"required#User account cannot be empty"
Password string p:"password" v:"required|password#PWD account cannot be empty"
UserSalt string
}
type UserAddRes struct {
}

func GetUserList(c *gin.Context, req *UserSearchReq) (res *UserSearchRes, err error) {
// todo
}

func UserAddReq(c *gin.Context, req *UserAddReq) (res *UserAddRes, err error) {
// todo
}

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

No branches or pull requests

3 participants
@HHC26 @JIeJaitt and others