swagger使用过程中遇到的坑

1、无限请求

如果swagger页面请求有错误,swagger会无限尝试访问,后面重启项目的时候,控制层会无限刷新出现日志的内容

本地的好办,如果项目项目部署到服务器中,可能十几分钟产生几个G的日志文件

解决方式:最简单的方式——关闭请求报错的浏览器

 

2、同名问题

@Api(同名的问题) 因为swagger会根据tags 的名称查找对象,有同名对象的时候,swagger的文档就会出现问题
如果swagger的某个API下出现不属于该API的请求,这个就是API的同名的问题,查找相同的API名称替换即可

 

3、类上的注解“/”的问题

@ApiModel(不能使用“/”)

Errors
Hide
Resolver error at paths./v1-0/Configuration/add.post.parameters.1.schema.properties.listHotCarBrandIVO.items.$ref
Could not resolve reference because of: Could not resolve pointer: /definitions/热门车/品牌/的IVO does not exist in document

 

4、使用map作为返回类型报错,

Errors
Hide
Resolver error at definitions.Map«string,List«卖车车辆信息OVO»».additionalProperties.$ref
Could not resolve reference because of: Could not resolve pointer: /definitions/List does not exist in document

  两个解决方案:升级swagger版本号,这个是我用2.8.0报错会报错,网上有说升级版本可以解决,这个我没有去试,

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

 我这边的解决方案是,将map定义在对象中,面向对象编程,而且这样生成文档的时候,注释也会显示好

 

5、swagger版本的问题,2.8之前的版本在  路径/{id} +@pathVarisble  这样的写法

  2.8之前,swagger给出的类型居然是body,需要用json的格式传这个很奇怪,

  版本更新到2.8以后,路径后面绑定的参数就是 swagger给出的类型居然是就能是param

  适当的更新版本有好处

		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.8.0</version>
		</dependency>
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.8.0</version>
		</dependency>

  

 6没有重现过的一个bug

 Failed to execute 'fetch' on 'Window': Failed to parse URL from http://localhost/8765undefindFailed to parse URL from http://localhost/8765undefind

  我一直重启项目 swagger没有重现问题

  后来我修改请求你方法上的api注释,重启就可以,可能是swagger上api冲突,关键是这个没有提示,好晕;如果谁找到重现这个问题来说一下

posted @ 2018-09-01 10:05  七分饱  阅读(59800)  评论(1编辑  收藏  举报