0

How do I make swagger-ui to show pre-populated real values in the Example box below? (The box for request model that shows when user clicks on "Try it out" button in swagger-ui).

I am using SpringBoot/Java and I would like it to show some real values rather than data types. It seam to do that for DOB field by default.

I have MyModel defined as below and I was expecting that using "value" in ApiModelProperty will set these values but it is not:

@ApiModel(description="blahblah")
public class MyModel {
    @ApiModelProperty(notes = "some notes", name = "name", required = true, value = "Bot")
    private String name;
  
    @ApiModelProperty(notes = "Date of birth", name = "dob", required = true)
    private OffsetDateTime dob;
  
    @ApiModelProperty(notes="How old", name = "age", required = true, value = "31")
    private Integer age;
  ...
}

enter image description here

I would like above to look like:

enter image description here

pixel
  • 9,653
  • 16
  • 82
  • 149
  • What are using to define this template? are you using a json/yaml? or is it defined in code? – Jonathan JOhx May 24 '21 at 19:10
  • Related (or duplicate): [How can I set a description and an example in Swagger with Swagger annotations?](https://stackoverflow.com/q/46584658/113116) – Helen May 25 '21 at 07:18

1 Answers1

1

Use example:

@ApiModelProperty(notes = "some notes", name = "name", required = true, example = "Bot")
private String name;
Helen
  • 87,344
  • 17
  • 243
  • 314