So I understand that if we want body parameters we have to have a schema, which I do. The issue is no matter how I try to define my schema it does not allow me to have multiple body parameters. Here is an example of one of the methods I have tried. Any help would be great!
swagger: '2.0' # This is your document metadata info: version: "0.0.1" title: Todo App schema: { } host: localhost:3000 schemes: - http - https consumes: - application/json produces: - application/x-www-form-urlencoded basePath: / paths: # This is a path endpoint. Change it. /tasks: post: description: | Add 'Task' object. parameters: # An example parameter that is in query and is required - name: name in: query description: unique object task name required: true schema: type: string - name: description in: query description: task description required: true schema: type: string responses: # Response code 200: description: Successful response # A schema describing your response object. # Use JSON Schema format schema: title: Return String type: string example: "Task added succesfully" 500: description: Error schema: type: string example: "Could not add Task"
If you are trying to send a body with multiple parameters, add an object model in the definitions section and refer it in your body parameter, see below (works with editor.swagger.io):
You can use the default key to specify the default value for an optional parameter. The default value is the one that the server uses if the client does not supply the parameter value in the request. The value type must be the same as the parameter's data type.
I'm not sure to understand your question...
Body [...] there can only be one body parameter
Your example nodes also are wrong, see here for more details.
swagger: '2.0' info: version: "0.0.1" title: Todo App host: localhost:3000 schemes: - http - https consumes: - application/json produces: - application/x-www-form-urlencoded basePath: / paths: # This is a path endpoint. Change it. /tasks: post: description: | Add 'Task' object. parameters: - name: task in: body description: task object required: true schema: $ref: '#/definitions/Task' responses: 200: description: Successful response schema: title: Return String type: string example: "Task added succesfully" 500: description: Error schema: type: string example: "Could not add Task" definitions: Task: description: Task object properties: name: type: string description: task object name description: type: string description: task description required: - name - description
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With