swagger Bug警告日志 WARN io.swagger.models.parameters.AbstractSerializableParameter - Illegal Default

Swagger每一个@ApiModelProperty注解里example属性都会进行非空判断.但是,它在判断的语句里只判断了null的情况,没有判断是空字符串的情况,所以解析数字的时候就会报这个异常

java.lang.NumberFormatException: For input string: ""

swagger-models 默认是1.5.20,这个版本是没有解决上面这个问题;而在较新的版本1.5.22是解决了这个问题。

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
            <exclusions>
                <exclusion>
                    <artifactId>swagger-models</artifactId>
                    <groupId>io.swagger</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
            <version>1.5.22</version>
            <exclusions>
                <exclusion>
                    <artifactId>swagger-annotations</artifactId>
                    <groupId>io.swagger</groupId>
                </exclusion>
            </exclusions>
        </dependency>
或者调整日志的级别
# application.yml
logging:
  level:
    io.swagger.models.parameters.AbstractSerializableParameter: error
# application.properties
logging.level.io.swagger.models.parameters.AbstractSerializableParameter=error

也可以给参数加默认值,可能比较多,这种方式需要改的地方太多

@ApiParam{name = "xxx", value = "xxxxx", required = true , example="1"}

@ApiModelProperty(value = "xxx",example="1")


版权声明:本文为Bruce1114原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。