go-gin-example icon indicating copy to clipboard operation
go-gin-example copied to clipboard

/auth 在路由中已经写成了 POST 方法,但是 swagger 中显示的是 GET

Open RussellCao824 opened this issue 4 years ago • 8 comments

刚下载了代码,发现在swagger页面中调用/auth一直显示 404 page not found。 查看代码发现,在routers/router.go中,/auth路由定义的是POST方法,而swagger页面中显示的是GET方法。 image image 之后,我在postman中使用post方法,带参数请求/auth,还是显示 404 page not foundimage 请问一下,是我使用的姿势不对吗?感谢。

RussellCao824 avatar Jul 30 '20 10:07 RussellCao824

swagger的页面能打开,但是没有一个接口能用的,不知道是不是我操作的问题 所有接口都是参数请求错误

woodyxiong avatar Aug 06 '20 07:08 woodyxiong

后面仔细看代码,发现是要这样访问的,后续的url都可以这样访问试试

curl --location --request POST 'http://127.0.0.1:8000/auth' \
--form 'username=test' \
--form 'password=test123456'

image

woodyxiong avatar Aug 06 '20 17:08 woodyxiong

同樣的問題,謝謝

bjk543 avatar Aug 09 '21 14:08 bjk543

这个项目标注的swag有点问题

caipeishen avatar Sep 24 '21 09:09 caipeishen

刚下载了代码,发现在swagger页面中调用/auth一直显示 404 page not found。 查看代码发现,在routers/router.go中,/auth路由定义的是POST方法,而swagger页面中显示的是GET方法。 image image 之后,我在postman中使用post方法,带参数请求/auth,还是显示 404 page not foundimage 请问一下,是我使用的姿势不对吗?感谢。

post请求,路径是【/auth】

caipeishen avatar Sep 24 '21 09:09 caipeishen

改下注释,执行swag init 现在的auth.go注释确实是get

// @Summary Get Auth
// @Produce  json
// @Param username query string true "userName"
// @Param password query string true "password"
// @Success 200 {object} app.Response
// @Failure 500 {object} app.Response
// @Router /auth [get]

alwaysbetter1314 avatar Mar 04 '22 09:03 alwaysbetter1314

修改 swag请求方式 并且如果请求为application/json方式 要修改GetAuth api中参数获取方法c.PostForm改为c.Query

dufeng-code avatar Jun 15 '22 09:06 dufeng-code

request url: http://127.0.0.1:8000/auth with POST body: username:test password:test123 can successfully get token.

code4happylife avatar Jul 28 '22 02:07 code4happylife