irpas技术客

illegal defaultvalue null for paramter type integer_sinat_29705095

大大的周 7622

一、问题

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


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #illegal #defaultValue #null #for #paramter #type #integer