We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
http://localhost:8000/swagger/index.html
The text was updated successfully, but these errors were encountered:
1、\app\form.go 里面对应接口入参封装 使用的是err := c.ShouldBind(v) ,这个的对应 表单提交类型,解析不了swagger提交的json对象类型,需要改成 err := c.ShouldBindJSON(v),就可以了。
2、就是封装入参的对象得加个对json解析的映射,例如json:"name", 例: type CreateTagRequest struct { Name string form:"name" json:"name" binding:"required,min=2,max=100" CreatedBy string form:"created_by" json:"created_by" binding:"required,min=2,max=100" State uint8 form:"state,default=1" json:"state" binding:"oneof=0 1" }
3、swagger注释修改, internal\routers\api\v1\tag.go
例如: // @summary 新增标签 // @produce json // @accept json // @param data body service.CreateTagRequest true "数据封装" // @success 200 {object} model.Tag "成功" // @failure 400 {object} errcode.Error "请求错误" // @failure 500 {object} errcode.Error "内部错误" // @router /api/v1/tags [post] func (t Tag) Create(c *gin.Context) { .......
还好是写得比较多java 接口,对swager还算熟悉,看着原接口每个参数都标有in body,觉得怪怪的,然后最后一个参数的内容覆盖前面的参数在请求体里面只有最后一个参数值,发现了问题。
跟着熊哥学go
Sorry, something went wrong.
b66be89
No branches or pull requests
http://localhost:8000/swagger/index.html
The text was updated successfully, but these errors were encountered: