首页 > 解决方案 > 嵌套复杂类型中的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);
}

标签: swaggerspringdocspringdoc-openapi-ui

解决方案


没有问题。您似乎没有使用正确的配置。

我们已经在这里回答了你:https ://github.com/springdoc/springdoc-openapi/issues/679


推荐阅读