swagger2打开doc页面时报错
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
我是用的swagger2版本是2.9.2,而此版本的swagger2引用的swagger基础包版本是1.5.20
[INFO] +- io.springfox:springfox-swagger2:jar:2.9.2:compile
[INFO] | +- io.swagger:swagger-annotations:jar:1.5.20:compile
[INFO] | +- io.swagger:swagger-models:jar:1.5.20:compile
如果在Integer类型的属性上使用@ApiModelProperty注解,并且没有写example默认值,就会报如下错误:
2019-10-10 17:28:58.214 WARN 7037 --- [http-nio-8011-exec-129] i.s.m.p.AbstractSerializableParameter Illegal DefaultValue null for parameter type integer
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:601)
at java.lang.Long.valueOf(Long.java:803)
at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412)
at sun.reflect.GeneratedMethodAccessor794.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
从日志来看,我们可以到类AbstractSerializableParameter,下面的方法getExample 一探究竟。
swagger-models-1.5.20.jar版本的getExample源码如下:this.example是String类型,默认是"", 所以在执行到 return Long.valueOf(this.example) 这行代码是就会报错。
@JsonProperty("x-example")
public Object getExample() {
if (this.example == null) {
return null;
} else {
try {
if ("integer".equals(this.type)) {
return Long.valueOf(this.example);
}
if ("number".equals(this.type)) {
return Double.valueOf(this.example);
}
if ("boolean".equals(this.type) && ("true".equalsIgnoreCase(this.example) || "false".equalsIgnoreCase(this.defaultValue))) {
return Boolean.valueOf(this.example);
}
} catch (NumberFormatException var2) {
LOGGER.warn(String.format("Illegal DefaultValue %s for parameter type %s", this.defaultValue, this.type), var2);
}
return this.example;
}
}
解决方法有2个:
1. 把Integer的属性@ApiModelProperty注解里都加上example,内容必须可以转为数字,比如:@ApiModelProperty(value = "年龄", example = "20")
2. 把swagger版本升级为1.5.21,下面是swagger-models-1.5.21.jar的源码:
@JsonProperty("x-example")
public Object getExample() {
if (this.example != null && !this.example.isEmpty()) {
try {
if ("integer".equals(this.type)) {
return Long.valueOf(this.example);
}
if ("number".equals(this.type)) {
return Double.valueOf(this.example);
}
if ("boolean".equals(this.type) && ("true".equalsIgnoreCase(this.example) || "false".equalsIgnoreCase(this.defaultValue))) {
return Boolean.valueOf(this.example);
}
} catch (NumberFormatException var2) {
LOGGER.warn(String.format("Illegal DefaultValue %s for parameter type %s", this.defaultValue, this.type), var2);
}
return this.example;
} else {
return this.example;
}
}
增加了!this.example.isEmpty() 的判断,isEmply()的源码如下:
public boolean isEmpty() {
return value.length == 0;
}
swagger2打开doc页面时报错的更多相关文章
- ecshop安装后打开管理页面时报500错误
昨天给朋友安装ecshop,遇到如下问题: 1.PHP不支持mysql扩展 打开http://localhost/install/index.php,第二步时候,报不支持mysql. ecshop是前 ...
- error while obtaining ui hierarchy xml file...用 uiautomatorviewer 获取安卓手机软件页面时报错
Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't ...
- 火狐浏览器调试ajax异步页面时报错NS_ERROR_UNEXPECTER
第一个直观的结论就是ajax调用出错,如果其他浏览器却调用没报错,而且正常返回值了,那么就是Firefox浏览器的问题了: 如果其他浏览器也没余完全正常执行,而是出现和我上一篇ajax向后台请求数据, ...
- vue-cli3使用vue-router 使用动态路由,在刷新页面时报错
刚发现的一个问题,在使用vue-cli3创建项目之后,使用动=动态路由,demo: { path: '/aa/:id', name: 'aa', component: aa }, 编程式路由: thi ...
- tomcat8.5打开manager页面报错的问题
之前用的8.0版本的tomcat,最近需要将版本升级,当前8的最新的版本是8.5.42,升级之后发现manager页面打不开了,就是下面这个按钮的页面 点击之后报403没权的错误 还是按照8.0版本的 ...
- vc6.0打开类向导时报错-Parsing error: Expected ";".Input Line: "解决方法
--------------------------- Microsoft Visual C++ --------------------------- Parsing error: Expecte ...
- EF:打开Oracle连接时报错
基础提供程序在 Open 上失败. The underlying provider failed on Open. 解决:安装最新的ODTwithODAC121024.
- tomcat已启动,使用maven的deploy发布后,根据路径打开浏览器访问时报错HTTP Status 500 - Error instantiating servlet class
web项目中请求出现错误,如下: HTTP Status 500 - Error instantiating servlet class XXXX类 type Exception report mes ...
- vue 访问页面时报错 Failed to compile
这个是因为node-sass没安装好,所以要重新安装 windows下运行命令:npm install node-sass --registry=https://registry.npm.taobao ...
随机推荐
- mysql逗号分隔问题
1.说明: 之前写了一个发先了有点问题, 用正则去匹配的会匹配多了数据,所以优化下 媒资表(asset_baseinfo)里面有地区,如下,如果一个节目包含多个地区,id存在如下 地区表(produc ...
- day52 html进阶
目录 一.分组与嵌套 二.伪类选择器 三.伪元素选择器 四.选择器优先级 五.css属性相关 1 字体属性 2 文字属性 3 背景图片 4 边框 5 display属性 6 盒子模型 7 浮动 一.分 ...
- Scala 基础(十二):Scala 函数式编程(四)高级(二)参数(类型)推断、闭包(closure)、函数柯里化(curry)、控制抽象
1 参数(类型)推断 参数推断省去类型信息(在某些情况下[需要有应用场景],参数类型是可以推断出来的,如list=(1,2,3) list.map() map中函数参数类型是可以推断的),同时也可以 ...
- Scala 基础(三):Scala语言快速开发入门
1.Scala执行流程分析 2.Scala程序开发注意事项(重点) Scala源文件以 “.scala" 为扩展名. Scala程序的执行入口是main()函数. Scala语言严格区分大小 ...
- MYSQL 之 JDBC(三): 增删改查(一)通过Statement执行更新操作
Statement测试 /** * 通过JDBC向指定的数据表中插入一条记录 * 1. Statement:用于执行sql语句的对象 * 1.1 通过Connection的createStatemen ...
- 目录(Python基础)
Python之介绍.基本语法.流程控制 Python之列表.字典.集合 Python之函数.递归.内置函数 Python之迭代器.装饰器.软件开发规范 Python之常用模块学习(一) Python之 ...
- MapReduce计算框架的核心编程思想
@ 目录 概念 MapReduce中常用的组件 概念 Job(作业) : 一个MapReduce程序称为一个Job. MRAppMaster(MR任务的主节点): 一个Job在运行时,会先启动一个进程 ...
- 绘图和可视化知识图谱-《利用Python进行数据分析》
所有内容整理自<利用Python进行数据分析>,使用MindMaster Pro 7.3制作,emmx格式,源文件已经上传Github,需要的同学转左上角自行下载或者右击保存图片. 其他章 ...
- tomcat 认证爆破之custom iterator使用
众所周知,BurpSuite是渗透测试最基本的工具,也可是神器,该神器有非常之多的模块:反正,每次翻看大佬们使用其的骚操作感到惊叹,这次我用其爆破模块的迭代器模式来练练手[不喜勿喷] 借助vulhub ...
- 小白入门python新手教程python
python教程很多,但是需要自学教程更好一些,看自学python教程3遍,然后一步步操作,7天后就会有很大的收货. 要向数据处理方向走,数据处理需要网络爬虫的知识,且更加精进.下面是我从网上查找这方 ...