Loading

illegal defaultvalue null for paramter type integer

一、问题

swagger2报错illegal defaultvalue null for paramter type integer

二、解决办法

正常swagger2引入

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>

修改依赖,覆盖默认的版本

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
    <exclusions>
        <exclusion>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/io.swagger/swagger-models -->
<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-models</artifactId>
    <version>1.5.21</version>
</dependency>

三、异常分析

异常信息可以看到关于swagger的堆栈信息

at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412)

点进去看之后,代码如下,默认引入1.5.20的包:
图片

注解的 example 默认值都是空字符串 "" ,包括ApiParam、ApiModelProperty、ApiImplicitParam等,经过上面的参数解析,null判断继续运行,执行xx.valueOf(),会打印警告

图片

1.5.21版本的如下,做了空值判断:

图片

github 同样的问题:

https://github.com/springfox/springfox/issues/2528

https://github.com/swagger-api/swagger-core/issues/2783

posted @ 2020-10-28 17:21  遗失的拂晓  阅读(486)  评论(0编辑  收藏  举报