gin-gonic / gin

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
https://gin-gonic.com/
MIT License
78.2k stars 7.98k forks source link

Automatically generate documents #4055

Open HHC26 opened 2 weeks ago

HHC26 commented 2 weeks ago

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 commented 1 week ago

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

HHC26 commented 6 days ago

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 commented 6 days ago

@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 }