Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger UI - nullable values

We have a SpringBoot (version 1.5.12) REST Api with springfox-swagger2 and springfox-swagger-ui (version 2.9.2)

Is it possible to have nullable properties in Swagger UI (using swagger.yaml configuration file or swagger annotations)?

The payload that we need to send is something like this:

{ 
  id: 2
  name: 'test'
  surname: null
}

Surname should be a string or null (by default null).
If not possible, can we override some swagger classes to obtain this behavior?

Thanks

like image 285
Fabry Avatar asked Jun 29 '26 17:06

Fabry


1 Answers

Yes it is possible to have nullable/optional properties. To do so set the required attribute in @ApiModelProperty (io.swagger.annotations) annotation to false (it is actually false by default).

@ApiModelProperty(required = false, value = "Surname")
private String surname;
like image 55
Vladas Maier Avatar answered Jul 01 '26 06:07

Vladas Maier