如何自定义请求主体的示例值并使用springdoc-open-api在swagger-ui上执行

问题描述

我已经使用springboot创建了rest webservice 并添加了springdoc-open-api,用于调试Web服务, 现在我有2个问题

1-如何在swagger-ui文档页面显示的请求中添加自定义测试值?

2-如何在swagger-ui文档页面上单击TRY IT OUT按钮执行请求?

有关其余的Web服务,请参考以下代码段:

@PostMapping(value="/result",consumes={ "application/json"},produces={ "application/json" } )
@Parameter(description  = "Student object need to calculate the score",name="InputObject",required = true )
public ResponseEntity<Result> displayResult(@Valid  @RequestBody Student request);

Public class Student{
  String name;
  String birthDate;
  String motherName;
  int rollNo;
  int seatNo;
}

Public class Result{
  int marks;
  String grade;
  double percentage;
}

I have tried to add value of request using @Schema(name = "name",example= "Rubeena",description = "Name of student"),is it right way to add the value in example request ?
Even after adding this schema when i click on TRY IT OUT button i dont get the outcome.

Is there any way to solve this problem?

解决方法

使用@Schema批注,我可以在示例请求中提供值

Public class Student{
@Schema(example= "XXX",description = "Name of student")
 String name;

@Schema(示例=“ 10-10-2020”,描述=“学生的出生日期”) 字符串birthDate; ...... }

,

在dto类中使用@ApiModelProperty注释。

示例-

scale_fill_discrete(labels = c('-O2','+O2'))