Question about multiple body parameters in Swagger documentation

1,048 views
Skip to first unread message

Scott Miller

unread,
Apr 2, 2016, 7:07:17 PM4/2/16
to Swagger
Hello,

I am new to Swagger and am using it to create the documentation for my API. I am manually writing a swagger.json file for my project and importing it to the editor at editor.swagger.io to view the result as I work.

I have done some research, and I can see that in order to have multiple parameters in the body of a result, one must use a schema. My code is as follows:

"parameters": [
   
{
       
"name": "user",
       
"in": "body",
       
"description": "name, email, and password",
       
"required": true,
       
"schema": {
           
"properties": {
               
"name": { "type": "string" },
               
"email": { "type": "string" },
               
"password": { "type": "string" }
           
}
       
}
   
}
]


This works fine to specify multiple body parameters, but of course the result is the following request:

POST /endpoint HTTP/1.1
Host: example.url.com
Content-Type: application/json
{
   
"name": "scott",
   
"email": "scottATmail.com",
   
"password": "my_pass"
}


Is there a way for me to specify Content-Type: application/x-www-form-urlencoded as follows:

POST /endpoint HTTP/1.1
Host: example.url.com
Content-Type: application/x-www-form-urlencoded


name
=scott&email=scott%40mail.com&password=my_pass


Thank you for your time and please let me know if I can provide any more info.

Ron Ratovsky

unread,
Apr 4, 2016, 12:10:16 AM4/4/16
to swagger-sw...@googlegroups.com
Hi Scott,

Those are not body parameters within the Swagger/OpenAPI terminology but rather formData parameters, each specifying a sing;e entry. 
Body parameters are intended as a single payload to the request.
 Hope this helps.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages