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 ...
随机推荐
- C#读取Excel转为DataTable
需要的Dll: NPOI.OOXML.dll https://files.cnblogs.com/files/CityOfThousandFires/NPOI.dl.rar /// <su ...
- Java标识符/数据类型,规范等详解
Java标识符 类名/变量名/方法名都称之为标识符. Java 所有的组成部分都需要名字.类名.变量名以及方法名都被称为标识符. 关于 Java 标识符,有以下几点需要注意: 所有的标识符都应该以字母 ...
- 题解:2018级算法第三次上机 C3-Zexal的浩瀚星辰
题目描述: 样例: 实现解释: 一道结合了火箭发射的贪心题目 知识点: 贪心,优先队列 题目分析: 根据题目描述可知,延迟后时间是正常推进的,也就是假设共有n个火箭,推迟k小时.则在到达k+1小时时, ...
- shell专题(十):Shell工具(重点)
10.1 cut cut的工作就是“剪”,具体的说就是在文件中负责剪切数据用的.cut 命令从文件的每一行剪切字节.字符和字段并将这些字节.字符和字段输出. 1.基本用法 cut [选项参数] fi ...
- Activiti工作流--分布式实现方案
一.运行环境 以下所有的描述都是基于Activiti的5.20.0.1版本 public interface ProcessEngine extends EngineServices { /** th ...
- 字符编码-Unicode、Utf-8 笔记
Unicode 将世界上所有的符号都纳入其中.每一个符号都给予一个独一无二的编码,那么乱码问题就会消失.这就是 Unicode,就像它的名字都表示的,这是一种所有符号的编码 UTF-8 UTF-8 就 ...
- disconf原理解析
前有了解过disconf,也知道它是基于zookeeper来做的,特意写了文章记录下自己的见解.如有错误,欢迎指正. 1.disconf-web会在启动时,将自身的host和配置文件注册到zookee ...
- python3将字符串unicode转换为中文
在我们的python使用过程中,可能会遇到这样的情况: 我们得到的中文数据是unicode编码类型的,这在python中是没有问题的,可以直接打印显示为中文. 但是,如果我们需要和其它语言或前端进行交 ...
- 评测Loki日志工具
评测Loki日志工具 目录 评测Loki日志工具 部署Loki 配置grafana 总结: 优势: 劣势: 本文仅对Loki进行简单评测,不涉及原理和细节. 部署Loki Loki是grafana团队 ...
- 题解 SP687 【REPEATS - Repeats】
考虑可以枚举字符串上的两个点,求出两个点所对应后缀的\(LCP\)和所对应前缀的\(LCS\),两点之间的距离为\(len\),则这两个点对答案的贡献为: \[ \frac{LCS+LCP+L-1}{ ...