gpt4 book ai didi

java - Swagger 文档中未显示嵌套对象

转载 作者:行者123 更新时间:2023-12-04 17:43:29 26 4
gpt4 key购买 nike

我在 2.9.2 版本上使用 swagger-springfox,我遇到了多个嵌套对象显示不完整的问题。
我有一个名为 AddEntityCaseReq 的类(class)和下面的结构。当我访问swagger-ui.htmlProperties中什么都没有.
我已标记 @ApiModel@ApiModelProperties在每个类(class)。有什么遗漏吗?

This is the class structure


AddEntityCaseReq
├── id
└── List<UploadDocuments> uploadDocuments;
└── Properties
├── id
└── name

This is the controller code


    @ResponseBody
@RequestMapping(value = "/addEntityCase", method = RequestMethod.POST)
@ApiOperation(value = "add entity case", notes = "add entity case")
@ApiImplicitParam(name = "addEntityCaseReq", value = "reuqest",
required = true, dataType = "AddEntityCaseReq")
public CommonResp<Boolean> addEntityCase(@RequestBody AddEntityCaseReq addEntityCaseReq) {
return addEntityCase.execute(addEntityCaseReq);
}

swagger model details here



swagger model details here

最佳答案

如果您在 openapi 中有类层次结构,您可能只会在 swagger ui 中看到基类。您可以做的是在配置中强制为更丰富的子类映射基类:

    return new Docket(DocumentationType.SWAGGER_2)
.securitySchemes(schemeList)
.alternateTypeRules( AlternateTypeRules.newRule(
typeResolver.resolve(LocalDate.class),
typeResolver.resolve(Date.class), Ordered.HIGHEST_PRECEDENCE),
AlternateTypeRules.newRule(
typeResolver.resolve(List.class, LocalDate.class),
typeResolver.resolve(List.class, String.class), Ordered.HIGHEST_PRECEDENCE),
AlternateTypeRules.newRule(
typeResolver.resolve(List.class, YourBaseClass.class),
typeResolver.resolve(List.class, YourRicherSubclass.class), Ordered.HIGHEST_PRECEDENCE)

)
.select()

这是映射列表的示例,但对于标准对象也一样。

关于java - Swagger 文档中未显示嵌套对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53311385/

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