1

I would like to add a description in Swagger documentation that some parameters in request body are optional.

Should I use @ApiParam annotation for such description ? I tried to use @ApiModelProperty(notes = "") but it didnt work.

@PostMapping(value = "/users/")
public ResponseEntity<Object> users(@RequestBody PostUserRequest postUserRequest) {}

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class PostUserRequest {
    @ApiParam(value = "This is optional parameter")
    private String phone;
}
LDropl
  • 846
  • 3
  • 9
  • 25

2 Answers2

1

You can use like this:

    @ApiModelProperty(value = "This parameter is optional", required = false)
Pavan
  • 543
  • 4
  • 16
1
  1. Take a look for @ApiModelProperty documentation: doc use value instead of notes (Currently not in use.)
  2. There is an answer for your question about which of this 2 is preferable link
Rustam
  • 378
  • 2
  • 6