@RequestParam Field With Default Value Marked Required
See original GitHub issueIf I have a @RequestParam
field with a default value like:
@RequestParam(value = "start", defaultValue = "0") int start
Springfox will still mark this field as required in the swagger.json. Per the contract in @RequestParam:
Supplying a default value implicitly sets required() to false.
It looks like the ParameterRequiredReader
should also check if the @RequestParam
has a defaultValue on it and if so, not set the field to be required.
Happy to submit a PR for this if you wish.
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Spring RequestParam default value Integer - TedBlob
We will discuss setting a default integer value for Spring RequestParam. This annotation binds a request parameter with a method parameter.
Read more >Is it possible to have empty RequestParam values use the ...
You can keep primitive type by setting default value, in the your case just add "required = false" property: @RequestParam(value = "i", required...
Read more >Spring @RequestParam Annotation - Baeldung
A detailed guide to Spring's @RequestParam annotation. ... a look at the annotation's attributes: name, value, required, and defaultValue.
Read more >RequestParam Example in Spring Boot REST
If the @RequestParam annotation is used and the default value is not provided, then this request parameter becomes required by default.
Read more >How to bind @RequestParam to object in Spring - Dev in Web
@RequestParam (required = false , defaultValue = "0" ) int offset, ... It should have a list of fields which match with request...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please read the first post. Also this is taken from the documentation:
Basically the code should go from:
boolean missingDefaultValue = ValueConstants.DEFAULT_NONE.equals(defaultValue) || (defaultValue == null || defaultValue.length() == 0);
to:
boolean missingDefaultValue = ValueConstants.DEFAULT_NONE.equals(defaultValue);
Anything other than ValueConstants.DEFAULT_NONE should be considered set by code, hence required should be set to false.
See #2296