SpringFox Swagger - Optional and Mandatory fields in model

Punter Vicky picture Punter Vicky · May 4, 2017 · Viewed 14.9k times · Source

I used SpringFox library for rest documentation of my spring boot app. When I click on model , all the elements are being returned as optional. Is there a way to display required elements as mandatory? Is there any additional configuration that needs to be added?

Answer

Ganesh picture Ganesh · May 4, 2017

Yes by default All the fields will be optional. To mark a field as required you can use following annotation.

@ApiModelProperty(required = true)

On the getter method of the field which should be required. This won't show the field as "mandatory". But the optional tag will be removed for this field in the documentation.

Hope this helps.