Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give a swagger parameter default value?

I want somes params on swagger have its own default value. Is there anyway to give a default value ? like this this note has to be filled automatically with "stackoverflow"

like image 694
godmankc Avatar asked Jan 06 '17 09:01

godmankc


People also ask

How do I set default value in Swagger?

Use the default keyword in the parameter schema 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.

How do you pass the optional parameter in Swagger?

By default, Swagger treats all request parameters as optional. You can add required: true to mark a parameter as required. Note that path parameters must have required: true , because they are always required. description: Numeric ID of the user to get.


1 Answers

You have to annotate your note parameter with defaultValue="stackoverflow".

You method signature should look like this:

public ResponseEntity<?> yourMethod(@ApiParam(value = "Default value for note", required = true, defaultValue = "stackoverflow") @Valid @RequestParam final String note) { }
like image 52
haihui Avatar answered Sep 22 '22 08:09

haihui