forked from yangxiufeng666/Micro-Service-Skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41380ae
commit 5b8ddf7
Showing
9 changed files
with
181 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...ava/com/microservice/skeleton/gateway/config/swagger/GatewaySwaggerResourcesProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.microservice.skeleton.gateway.config.swagger; | ||
|
||
import org.springframework.cloud.netflix.zuul.filters.Route; | ||
import org.springframework.cloud.netflix.zuul.filters.RouteLocator; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.stereotype.Component; | ||
import springfox.documentation.swagger.web.SwaggerResource; | ||
import springfox.documentation.swagger.web.SwaggerResourcesProvider; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* Description: | ||
* User: Mr.Yangxiufeng | ||
* Date: 2018-04-18 | ||
* Time: 14:56 | ||
*/ | ||
@Component | ||
@Primary | ||
public class GatewaySwaggerResourcesProvider implements SwaggerResourcesProvider { | ||
private final RouteLocator routeLocator; | ||
|
||
public GatewaySwaggerResourcesProvider(RouteLocator routeLocator) { | ||
this.routeLocator = routeLocator; | ||
} | ||
|
||
@Override | ||
public List<SwaggerResource> get() { | ||
List<SwaggerResource> resources = new ArrayList<>(); | ||
List<Route> routes = routeLocator.getRoutes(); | ||
for (Route route:routes) { | ||
resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"))); | ||
} | ||
return resources; | ||
} | ||
private SwaggerResource swaggerResource(String name, String location) { | ||
SwaggerResource swaggerResource = new SwaggerResource(); | ||
swaggerResource.setName(name); | ||
swaggerResource.setLocation(location); | ||
swaggerResource.setSwaggerVersion("2.0"); | ||
return swaggerResource; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ateway/src/main/java/com/microservice/skeleton/gateway/config/swagger/Swagger2Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.microservice.skeleton.gateway.config.swagger; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import springfox.documentation.builders.ApiInfoBuilder; | ||
import springfox.documentation.service.ApiInfo; | ||
import springfox.documentation.service.Contact; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* Description: | ||
* User: Mr.Yangxiufeng | ||
* Date: 2018-04-18 | ||
* Time: 14:55 | ||
*/ | ||
@Configuration | ||
@EnableSwagger2 | ||
public class Swagger2Config { | ||
@Bean | ||
public Docket createRestApi() { | ||
return new Docket(DocumentationType.SWAGGER_2) | ||
.apiInfo(apiInfo()); | ||
} | ||
|
||
private ApiInfo apiInfo() { | ||
return new ApiInfoBuilder() | ||
.title("说明文档") | ||
.description("接口说明文档") | ||
.termsOfServiceUrl("") | ||
.contact(new Contact("杨秀峰","[email protected]","[email protected]")) | ||
.version("1.0") | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
mss-resource/src/main/java/com/microservice/skeleton/resource/config/Swagger2Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.microservice.skeleton.resource.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import springfox.documentation.builders.ApiInfoBuilder; | ||
import springfox.documentation.builders.PathSelectors; | ||
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import springfox.documentation.service.ApiInfo; | ||
import springfox.documentation.service.Contact; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* Description: | ||
* User: Mr.Yangxiufeng | ||
* Date: 2018-04-18 | ||
* Time: 14:52 | ||
*/ | ||
@EnableSwagger2 | ||
@Configuration | ||
public class Swagger2Config { | ||
@Bean | ||
public Docket createRestApi() { | ||
return new Docket(DocumentationType.SWAGGER_2) | ||
.apiInfo(apiInfo()) | ||
.select() | ||
.apis(RequestHandlerSelectors.basePackage("com.microservice.skeleton.resource.controller")) | ||
.paths(PathSelectors.any()) | ||
.build(); | ||
} | ||
|
||
private ApiInfo apiInfo() { | ||
return new ApiInfoBuilder() | ||
.title("resource文档") | ||
.description("resource接口说明文档") | ||
.termsOfServiceUrl("") | ||
.contact(new Contact("杨秀峰","[email protected]","[email protected]")) | ||
.version("1.0") | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters