Commit acb459a7 authored by Junling Bu's avatar Junling Bu
Browse files

chore: 引入swagger-bootstrap-ui

parent b33db760
......@@ -142,4 +142,7 @@ litemall:
endpoint: http://pd5cb6ulu.bkt.clouddn.com
accessKey: 111111
secretKey: xxxxxx
bucketName: litemall
\ No newline at end of file
bucketName: litemall
swagger:
production: true
\ No newline at end of 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 安全服务
......
......@@ -142,4 +142,7 @@ litemall:
endpoint: http://pd5cb6ulu.bkt.clouddn.com
accessKey: 111111
secretKey: xxxxxx
bucketName: litemall
\ No newline at end of file
bucketName: litemall
swagger:
production: true
\ No newline at end of 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>
......
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() {
......
......@@ -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");
......
......@@ -13,4 +13,7 @@ logging:
org.springframework: ERROR
org.mybatis: ERROR
org.linlinjava.litemall.admin: DEBUG
org.linlinjava.litemall: ERROR
\ No newline at end of file
org.linlinjava.litemall: ERROR
swagger:
production: false
\ No newline at end of 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
\ No newline at end of file
config: classpath:logback-spring.xml
swagger:
production: false
\ No newline at end of file
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() {
......
......@@ -13,4 +13,7 @@ logging:
org.springframework: ERROR
org.mybatis: ERROR
org.linlinjava.litemall.wx: DEBUG
org.linlinjava.litemall: ERROR
\ No newline at end of file
org.linlinjava.litemall: ERROR
swagger:
production: false
\ No newline at end of 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>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment