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

Rub*_*ena 5 java rest swagger-ui spring-boot springdoc-openapi-ui

我已经使用 springboot 创建了rest webservice,并添加了 springdoc-open-api 用于 webservice 的文档,现在我有 2 个问题

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

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

请参考下面的代码片段来获取其余的网络服务:

@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?
Run Code Online (Sandbox Code Playgroud)

Rub*_*ena 8

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

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

@Schema(example= "10-10-2020", description = "学生的出生日期") StringbirthDate; ……}


Ayu*_*h v 1

在 dto 类中使用 @ApiModelProperty 注释。

例子 -

Public class Student{
   @ApiModelProperty(value = "name", name = "name", dataType = "String" example = "Rube")
  String name;
   @ApiModelProperty(value = "birthDate", name = "birthDate", dataType = "birthDate" example = "12/12/1995")
  String birthDate;
 ........................
}

//should work with following dependencies 
     <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
Run Code Online (Sandbox Code Playgroud)