Swagger递归地解决类型的依赖关系(无限循环)

问题描述 投票:0回答:1

[我们想将Swagger用于现有的Spring-boot项目(> 70模型,> 250端点),并且在设置Swagger时遇到了应用程序无法启动且进入无限循环的问题。

  • 日志
...
[DEBUG] 2020-01-04 23:28:32.500 Recursively resolving dependencies for type X;
[DEBUG] 2020-01-04 23:28:32.500 Adding type X2; for parameter x2
[DEBUG] 2020-01-04 23:28:32.501 Recursively resolving dependencies for type X2;
[DEBUG] 2020-01-04 23:28:32.501 Adding type Ljava/util/List<X3>; for parameter x3s
[DEBUG] 2020-01-04 23:28:32.501 Adding collectionElement type X3;
[DEBUG] 2020-01-04 23:28:32.501 Recursively resolving dependencies for collectionElement type X3;
[DEBUG] 2020-01-04 23:28:32.501 Adding type Ljava/util/List<X4;>; for parameter x4s
[DEBUG] 2020-01-04 23:28:32.501 Adding collectionElement type X4;
[DEBUG] 2020-01-04 23:28:32.501 Recursively resolving dependencies for collectionElement type X4;
...
  • POM
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
...
    <dependencies>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        ....
    <dependencies>

任何帮助表示赞赏,甚至包括一些有关如何深入研究此问题的提示,因为日志没有帮助,我也不知道从哪里开始!如果您需要更多详细信息,请告诉我。

java spring spring-boot swagger springfox
1个回答
0
投票

遇到了同样的问题,由于弹簧的魔力,我们最终使用id而不是整个对象来解决此问题。只需为导致问题的参数添加@ApiIgnore,然后手动添加ApiImplicitParam,例如

@ApiImplicitParam(
    required = true,
    value = "XxxId, of provided Xxx. Not Required",
    paramType = "query",
    dataType = "int"
)
@GetMapping(value = ["/XXX_PATH"])
fun getYyy(
    @ApiIgnore @RequestParam(required = false, value = Xxx_ID) xxx: Xxx?
): List<Yyy>
© www.soinside.com 2019 - 2024. All rights reserved.