Home > other >  Add description in Swagger for optional parameters in request body
Add description in Swagger for optional parameters in request body

Time:11-29

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;
}

CodePudding user response:

You can use like this:

    @ApiModelProperty(value = "This parameter is optional", required = false)

CodePudding user response:

  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
  • Related