Skip to content

Commit 930e0c5

Browse files
authored
Merge pull request #2 from SpringForAll/master
同步一下
2 parents 447382d + 7f68606 commit 930e0c5

File tree

6 files changed

+287
-36
lines changed

6 files changed

+287
-36
lines changed

README.md

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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

@@ -9,7 +9,7 @@
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

@@ -26,12 +26,14 @@
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
8082
swagger.globalOperationParameters[1].modelRef=string
8183
swagger.globalOperationParameters[1].parameterType=body
8284
swagger.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)

pom.xml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>com.didispace</groupId>
8-
<artifactId>spring-boot-starter-swagger</artifactId>
9-
<version>1.4.1.RELEASE</version>
7+
<groupId>com.spring4all</groupId>
8+
<artifactId>swagger-spring-boot-starter</artifactId>
9+
<version>1.6.0.RELEASE</version>
1010

1111
<name>spring-boot-starter-swagger</name>
12-
<url>https://github.com/dyc87112/spring-boot-starter-swagger</url>
12+
<url>https://github.com/SpringForAll/spring-boot-starter-swagger</url>
1313
<description>starter for swagger2</description>
1414

1515
<parent>
@@ -27,9 +27,9 @@
2727
</licenses>
2828

2929
<scm>
30-
<url>http://didispace.com</url>
31-
<connection>[email protected]:dyc87112/spring-boot-starter-swagger.git</connection>
32-
<developerConnection>https://github.com/dyc87112/spring-boot-starter-swagger</developerConnection>
30+
<url>http://spring4all.com</url>
31+
<connection>[email protected]:SpringForAll/spring-boot-starter-swagger.git</connection>
32+
<developerConnection>https://github.com/SpringForAll/spring-boot-starter-swagger</developerConnection>
3333
</scm>
3434

3535
<developers>
@@ -84,6 +84,11 @@
8484
<version>1.16.12</version>
8585
<scope>provided</scope>
8686
</dependency>
87+
<dependency>
88+
<groupId>org.springframework.boot</groupId>
89+
<artifactId>spring-boot-starter-web</artifactId>
90+
<optional>true</optional>
91+
</dependency>
8792
</dependencies>
8893

8994
<dependencyManagement>
@@ -113,4 +118,4 @@
113118
</plugin>
114119
</plugins>
115120
</build>
116-
</project>
121+
</project>

src/main/java/com/didispace/swagger/EnableSwagger2Doc.java renamed to src/main/java/com/spring4all/swagger/EnableSwagger2Doc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.didispace.swagger;
1+
package com.spring4all.swagger;
22

33
import org.springframework.context.annotation.Import;
44

src/main/java/com/didispace/swagger/Swagger2Configuration.java renamed to src/main/java/com/spring4all/swagger/Swagger2Configuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.didispace.swagger;
1+
package com.spring4all.swagger;
22

33
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
44
import org.springframework.context.annotation.Configuration;

0 commit comments

Comments
 (0)