chore: 引入swagger-bootstrap-ui

This commit is contained in:
Junling Bu
2020-06-04 16:00:09 +08:00
parent b33db76021
commit acb459a74b
11 changed files with 49 additions and 15 deletions

View File

@@ -142,4 +142,7 @@ litemall:
endpoint: http://pd5cb6ulu.bkt.clouddn.com
accessKey: 111111
secretKey: xxxxxx
bucketName: litemall
bucketName: litemall
swagger:
production: true

View File

@@ -439,11 +439,26 @@ API应该存在版本控制以保证兼容性。
造成代码不是很简洁。特别是具备代码属性的注解和Swagger文档注解混杂在一起可能不是很好。
当然本项目也简单地配置了Swagger(见`WxSwagger2Configuration``AdminSwagger2Configuration`)
在线Swagger文档链接http://122.51.199.160:8080/swagger-ui.html
* 在线Swagger文档链接http://122.51.199.160:8080/swagger-ui.html
* 本地Swagger文档链接http://localhost:8080/swagger-ui.html
此外也使用了swagger-bootstrap-ui对Swagger进一步增强了使用效果。
* 在线swagger-bootstrap-ui文档链接http://122.51.199.160:8080/doc.html
* 本地swagger-bootstrap-ui文档链接http://localhost:8080/doc.html
当然正如上文讨论本项目不是很接受Swagger的理念所以后端没有使用Swagger的相关文档注解
这也导致了Swagger接口文档的不具可读性。如果开发者需要可以自行在后端补充Swagger注解。
需要注意的是:
> 这里接口默认是公开的因此项目一旦需要上线请及时删除swagger和swagger-bootstrap-ui依赖和配置
> 或者采取其他手段,防止接口对外暴露造成**安全隐患**。
例如
```
swagger:
production: false
```
## 2 商城API服务
### 2.1 安全服务

View File

@@ -142,4 +142,7 @@ litemall:
endpoint: http://pd5cb6ulu.bkt.clouddn.com
accessKey: 111111
secretKey: xxxxxx
bucketName: litemall
bucketName: litemall
swagger:
production: true

View File

@@ -40,6 +40,11 @@
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring-boot-web-starter</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
</dependencies>
<build>

View File

@@ -1,7 +1,9 @@
package org.linlinjava.litemall.admin.config;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
@@ -20,6 +22,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class AdminSwagger2Configuration {
@Bean
public Docket adminDocket() {

View File

@@ -33,13 +33,7 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/admin/auth/401", "anon");
filterChainDefinitionMap.put("/admin/auth/index", "anon");
filterChainDefinitionMap.put("/admin/auth/403", "anon");
filterChainDefinitionMap.put("/admin/index/index", "anon");
filterChainDefinitionMap.put("/swagger-ui.html", "anon");
filterChainDefinitionMap.put("/swagger-resources", "anon");
filterChainDefinitionMap.put("/swagger-resources/configuration/security", "anon");
filterChainDefinitionMap.put("/swagger-resources/configuration/ui", "anon");
filterChainDefinitionMap.put("/v2/api-docs", "anon");
filterChainDefinitionMap.put("/webjars/springfox-swagger-ui/**", "anon");
filterChainDefinitionMap.put("/admin/index/*", "anon");
filterChainDefinitionMap.put("/admin/**", "authc");
shiroFilterFactoryBean.setLoginUrl("/admin/auth/401");

View File

@@ -13,4 +13,7 @@ logging:
org.springframework: ERROR
org.mybatis: ERROR
org.linlinjava.litemall.admin: DEBUG
org.linlinjava.litemall: ERROR
org.linlinjava.litemall: ERROR
swagger:
production: false

View File

@@ -16,4 +16,7 @@ server:
mime-types: application/javascript,text/css,application/json,application/xml,text/html,text/xml,text/plain
logging:
config: classpath:logback-spring.xml
config: classpath:logback-spring.xml
swagger:
production: false

View File

@@ -1,5 +1,6 @@
package org.linlinjava.litemall.wx.config;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
@@ -20,6 +21,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class WxSwagger2Configuration {
@Bean
public Docket wxDocket() {

View File

@@ -13,4 +13,7 @@ logging:
org.springframework: ERROR
org.mybatis: ERROR
org.linlinjava.litemall.wx: DEBUG
org.linlinjava.litemall: ERROR
org.linlinjava.litemall: ERROR
swagger:
production: false

View File

@@ -159,14 +159,14 @@
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.3</version>
<version>1.9.6</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.1-jre</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>