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

标签 java spring-boot rest swagger-ui springdoc-openapi-ui

我使用 springboot 创建了rest webservice
并添加了 springdoc-open-api 用于 webservice 的文档化,
现在我有两个问题
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?

最佳答案

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

Public class Student{
@Schema(example= "XXX", description = "Name of student")
 String name;
@Schema(example="10-10-2020", description = "学生的出生日期")
字符串生日;
......
}

关于java - 如何自定义请求正文的示例值并使用 springdoc-open-api 在 swagger-ui 上执行它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64501089/

相关文章:

java - 如何从 wsimport 生成 SoapProxy?

java - Thymeleaf 启动时出错

rest - 如果一个 API 只提供 POST 请求功能,它是 RESTful 的吗?

asp.net - 在 IIS 上休息

java - 我一直收到 "The operator == is undefined for the argument type(s) boolean, int"并且不知道如何修复它

java - 创建每行和每列中具有唯一字符的二维字符表

java - Mockito - 如何忽略私有(private)成员对象的方法调用?

java - 无法加载驱动程序类 org.mariadb.jdbc.Driver

java - Spring-boot:需要一个名为 'entityManagerFactory' 的 bean,但找不到

java - 通过 JSON Rest Server (Jersey) 和 Android 进行通信