gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:23:41 27 4
gpt4 key购买 nike

我使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com