swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.7k stars 1.2k forks source link

Add suuport application/x-www-form-urlencoded #108

Closed Lack30 closed 6 years ago

Lack30 commented 6 years ago
// @Summary 添加用户
// @accept multipart/form-data
// @Produce json
// @Param email formData string true "用户邮箱地址"
// @Param username formData string true "用户名"
// @Param password formData string true "用户密码"
// @Success 200 {string} json "{"code":200,"data":[],"msg":{"title":"ok"}}"
// @Router /api/v1/users [post]

Then use the command swag init.But...

...
...
 "parameters": [
     {
         "type": "file",
         "description": "用户邮箱
         "name": "email",
         "in": "formData",
         "required": true
     },
     {
         "type": "file",
         "description": "用户名",
         "name": "username",
         "in": "formData",
         "required": true
     },
     {
         "type": "file",
         "description": "用户密码
         "name": "password",
         "in": "formData",
         "required": true
     }
 ],
...
...
pei0804 commented 6 years ago

How do you want format?

Lack30 commented 6 years ago

I want string type not file string I want

 "parameters": [
     {
         "type": "string",
         "description": "用户邮箱
         "name": "email",
         "in": "formData",
         "required": true
     },
     {
         "type": "string",
         "description": "用户名",
         "name": "username",
         "in": "formData",
         "required": true
     },
     {
         "type": "string",
         "description": "用户密码
         "name": "password",
         "in": "formData",
         "required": true
     }
 ],

not

 "parameters": [
     {
         "type": "file",
         "description": "用户邮箱
         "name": "email",
         "in": "formData",
         "required": true
     },
     {
         "type": "file",
         "description": "用户名",
         "name": "username",
         "in": "formData",
         "required": true
     },
     {
         "type": "file",
         "description": "用户密码
         "name": "password",
         "in": "formData",
         "required": true
     }
 ],
pei0804 commented 6 years ago

OK. I'll check.

pei0804 commented 6 years ago

Why do you use multipart/form-data? I think not necessary.

pei0804 commented 6 years ago

Do you want to use application/x-www-form-urlencoded?

Lack30 commented 6 years ago

Yes! Can you help me?

pei0804 commented 6 years ago

for you https://github.com/swaggo/swag/pull/115.

Lack30 commented 6 years ago

Can you give me an example?