swagger - 嵌套复杂类型中的SpringDoc swagger文档生成异常
问题描述
我们有一个 Person 类。Person 类有一个 PersonDetail 类型的属性。而且 PersonDetail 有一个 Mail 类的属性。
当我们启动应用程序并导航到 swagger ui html 页面时,未在 openapi 定义的组件部分生成 Mail 类,我们得到“无法解析引用:无法解析指针:/components/schemas/Mail 不存在于文档中”页面错误。当我们检查第三级是否存在复杂类型时,springdoc 无法解析该类型。Person 和 PersonDetail 工作正常,但 Mail 失败。
人员->人员详细信息->邮件
public class Person {
private String name;
private PersonDetail personDetail;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public PersonDetail getPersonDetail() {
return personDetail;
}
public void setPersonDetail(PersonDetail personDetail) {
this.personDetail = personDetail;
}
}
public class PersonDetail {
private String surname;
private List<Mail> mails;
public List<Mail> getMails() {
return mails;
}
public void setMails(List<Mail> mails) {
this.mails = mails;
}
}
public class Mail {
private String mailAddress;
public String getMailAddress() {
return mailAddress;
}
public void setMailAddress(String mailAddress) {
this.mailAddress = mailAddress;
}
}
@get(path = "/getPersonTest")
@operation(description = "Testttt")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "successful operation",
content = @content(schema = @Schema(implementation = Person.class)))})
public ResponseEntity getPerson(@RequestParam String name){
Person person = new Person();
return ResponseEntity.status(HttpStatus.OK).body(person);
}
解决方案
没有问题。您似乎没有使用正确的配置。
我们已经在这里回答了你:https ://github.com/springdoc/springdoc-openapi/issues/679
推荐阅读
- excel - 使用第五多项式从给定 X 值返回 Y 值的 UDF
- android - android - 通过适配器更改 RecyclerView 项目图标
- angular - 'mat-card-content' 不是已知元素:
- variables - 如何命名指示是否做某事的布尔变量?
- java - 新的Spring项目文件结构说明
- javascript - 如何检查函数是否存在
- spring-boot - 带有大摇大摆生成接口的 ResponseEntity 返回类型通配符
- android - CoordinatorLayout 中 AppBarLayout 下面的 WebView 不起作用
- angular - Angular 9 中同步融合调度程序库中更改日期后的时间块中未显示事件?
- javascript - 反应本机取消 setTimeout