11# 简介
22
3- [ ![ Build Status] ( https://travis-ci.org/dyc87112/spring-boot-starter-swagger.svg?branch=master )] ( https://travis-ci.org/dyc87112/spring-boot-starter-swagger )
3+ [ ![ Build Status] ( https://travis-ci.org/dyc87112/spring-boot-starter-swagger.svg?branch=1.5.0 )] ( https://travis-ci.org/dyc87112/spring-boot-starter-swagger )
44
55该项目主要利用Spring Boot的自动化配置特性来实现快速的将swagger2引入spring boot应用来生成API文档,简化原生使用swagger2的整合代码。
66
99 - 码云:https://gitee.com/didispace/spring-boot-starter-swagger
1010- 使用样例:https://github.com/dyc87112/swagger-starter-demo
1111- 我的博客:http://blog.didispace.com
12- - 我们社区:http://spring4all.com
12+ - 我们社区:http://www. spring4all.com
1313
1414** 小工具一枚,欢迎使用和Star支持,如使用过程中碰到问题,可以提出Issue,我会尽力完善该Starter**
1515
2626
2727``` xml
2828<dependency >
29- <groupId >com.didispace </groupId >
30- <artifactId >spring-boot-starter-swagger </artifactId >
31- <version >1.4.1 .RELEASE</version >
29+ <groupId >com.spring4all </groupId >
30+ <artifactId >swagger- spring-boot-starter</artifactId >
31+ <version >1.6.0 .RELEASE</version >
3232</dependency >
3333```
3434
35+ ** 注意:从` 1.6.0 ` 开始,我们按Spring Boot官方建议修改了artifactId为` swagger-spring-boot-starter ` ,1.6.0之前的版本不做修改,依然为使用` spring-boot-starter-swagger ` !**
36+
3537- 在应用主类中增加` @EnableSwagger2Doc ` 注解
3638
3739``` java
@@ -80,13 +82,24 @@ swagger.globalOperationParameters[1].description=some description two
8082swagger.globalOperationParameters[1].modelRef =string
8183swagger.globalOperationParameters[1].parameterType =body
8284swagger.globalOperationParameters[1].required =false
85+
86+ // 取消使用默认预定义的响应消息,并使用自定义响应消息
87+ swagger.apply-default-response-messages =false
88+ swagger.global-response-message.get[0].code =401
89+ swagger.global-response-message.get[0].message =401get
90+ swagger.global-response-message.get[1].code =500
91+ swagger.global-response-message.get[1].message =500get
92+ swagger.global-response-message.get[1].modelRef =ERROR
93+ swagger.global-response-message.post[0].code =500
94+ swagger.global-response-message.post[0].message =500post
95+ swagger.global-response-message.post[0].modelRef =ERROR
8396```
8497
8598## 配置说明
8699
87100### 默认配置
88101
89- ```
102+ ``` properties
90103- swagger.enabled =是否启用swagger,默认:true
91104- swagger.title =标题
92105- swagger.description =描述
@@ -142,7 +155,7 @@ swagger.exclude-path=/ops/**, /error
142155
143156具体配置内容如下:
144157
145- ```
158+ ``` properties
146159- swagger.docket.<name>.title =标题
147160- swagger.docket.<name>.description =描述
148161- swagger.docket.<name>.version =版本
@@ -190,7 +203,7 @@ swagger.docket.bbb.basePackage=com.yonghui
190203
191204说明:默认配置与分组配置可以一起使用。在分组配置中没有配置的内容将使用默认配置替代,所以默认配置可以作为分组配置公共部分属性的配置。` swagger.docket.aaa.globalOperationParameters[0].name ` 会覆盖同名的全局配置。
192205
193- ### JSR-303校验注解支持
206+ ### JSR-303校验注解支持(1.5.0 + 支持)
194207
195208支持对JSR-303校验注解的展示,如下图所示:
196209
@@ -203,7 +216,68 @@ swagger.docket.bbb.basePackage=com.yonghui
203216- ` @Size `
204217- ` @Pattern `
205218
219+ ### 自定义全局响应消息配置(1.6.0 + 支持)
220+
221+ 支持 POST,GET,PUT,PATCH,DELETE,HEAD,OPTIONS,TRACE 全局响应消息配置,配置如下
222+
223+ ``` properties
224+ // 取消使用默认预定义的响应消息,并使用自定义响应消息
225+ swagger.apply-default-response-messages =false
226+ swagger.global-response-message.get[0].code =401
227+ swagger.global-response-message.get[0].message =401get
228+ swagger.global-response-message.get[1].code =500
229+ swagger.global-response-message.get[1].message =500get
230+ swagger.global-response-message.get[1].modelRef =ERROR
231+ swagger.global-response-message.post[0].code =500
232+ swagger.global-response-message.post[0].message =500post
233+ swagger.global-response-message.post[0].modelRef =ERROR
234+ ```
235+
236+ ### UI功能配置(1.6.0 + 支持)
237+
238+ - 调试按钮的控制(try it out)
239+
240+ ``` properties
241+ swagger.ui-config.submit-methods =get,delete
242+ ```
243+
244+ 该参数值为提供调试按钮的HTTP请求类型,多个用,分割。
245+
246+ 如果不想开启调试功能,只需要如下设置即可:
247+
248+ ``` properties
249+ swagger.ui-config.submit-methods =
250+ ```
251+
252+ - 其他配置
253+
254+ ``` properties
255+ # json编辑器
256+ swagger.ui-config.json-editor =false
257+ # 显示请求头
258+ swagger.ui-config.show-request-headers =true
259+ # 页面调试请求的超时时间
260+ swagger.ui-config.request-timeout =5000
261+ ```
262+
263+ ### ignoredParameterTypes配置(1.6.0 + 支持)
264+
265+ ``` properties
266+ # 基础配置
267+ swagger.ignored-parameter-types[0]=com.didispace.demo.User
268+ swagger.ignored-parameter-types[1]=com.didispace.demo.Product
269+
270+ # 分组配置
271+ swagger.docket.aaa.ignored-parameter-types[0]=com.didispace.demo.User
272+ swagger.docket.aaa.ignored-parameter-types[1]=com.didispace.demo.Product
273+ ```
274+
275+ > 该参数作用:
276+ > Q. Infinite loop when springfox tries to determine schema for objects with nested/complex constraints?
277+ > A. If you have recursively defined objects, I would try and see if providing an alternate type might work or perhaps even ignoring the offending classes e.g. order using the docket. ignoredParameterTypes(Order.class). This is usually found in Hibernate domain objects that have bidirectional dependencies on other objects.
278+
206279## 贡献者
207280
208281- [ 程序猿DD-翟永超] ( https://github.com/dyc87112/ )
209282- [ 小火] ( https://renlulu.github.io/ )
283+ - [ 泥瓦匠BYSocket] ( https://github.com/JeffLi1993 )
0 commit comments