Open Source: API documentation summary of management tools Swagger Butler

Swagger Butler is based API documentation Swagger and build Zuul collection tool. By building a simple application Spring Boot, the configuration will be able to increase the number of existing integrated API documentation Swagger Web applications are aggregated together for easy viewing and testing.

project address

  • Github:https://github.com/dyc87112/swagger-butler
  • Gitee:https://gitee.com/didispace/swagger-butler

manual

Getting Started

When the tool is very simple, first simple entry through the following steps:

The first step : to build a foundation of Spring Boot application

If you do not know how to create a Spring Boot application, you can Read this introductory article

Step Two : introducing dependency in pom.xml

<parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>1.5.10.RELEASE</version>
</parent>
<dependencies>
 <dependency>
 <groupId>com.didispace</groupId>
 <artifactId>swagger-butler-core</artifactId>
 <version>1.0.0</version>
 </dependency>
</dependencies>

Step Three : Create Main Class, increase @EnableSwaggerButler comment function to open Swagger Butler

@EnableSwaggerButler
@SpringBootApplication
public class StaticApplication {
 public static void main(String[] args) {
 SpringApplication.run(StaticApplication.class);
 }
}

The fourth step : the configuration file to increase Swagger document address configuration

spring.application.name=swagger-butler-example-static
server.port=11000
zuul.routes.service-a.path=/service-a/**
zuul.routes.service-a.url=http://localhost:10010/
swagger.butler.resources[0].name=service-a
swagger.butler.resources[0].url=/service-a/v2/api-docs
swagger.butler.resources[0].swagger-version=2.0
zuul.routes.service-b.path=/service-b/**
zuul.routes.service-b.url=http://localhost:10020/
swagger.butler.resources[1].name=service-b
swagger.butler.resources[1].url=/service-b/v2/api-docs
swagger.butler.resources[1].swagger-version=2.0

The above position is configured with two documents, since there is also no service discovery mechanism introduced, so you need to use zuul to configure access to the application request is forwarded to a specific service routing rules. Then get specific information pointing to an interface link swagger of json configuration files in the configuration resource.

Step Five : Visit http: // localhost: 11000 / swagger -ui.html

 

Example

Specific examples of the code visible swagger-butler-example-static directory

Principle visible: Spring Cloud Zuul use Swagger API interface documentation summary

Integration with eureka

When integrated eureka get all API documentation at the registration center, only need to add the following configuration on the basis of the above works:

The first step : pom.xml increase eureka dependent, such as:

<dependencies>
 <dependency>
 <groupId>com.didispace</groupId>
 <artifactId>swagger-butler-core</artifactId>
 <version>1.0.0</version>
 </dependency>
 <dependency>
 <groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-starter-eureka</artifactId>
 <version>1.3.2.RELEASE</version>
 </dependency>
</dependencies>

Step : Main Class increased @EnableDiscoveryClient, such as:

@EnableDiscoveryClient
@EnableSwaggerButler
@SpringBootApplication
public class EurekaApplication {
 public static void main(String[] args) {
 SpringApplication.run(EurekaApplication.class);
 }
}

The third step : the configuration file to increase eureka configuration, such as:

spring.application.name=swagger-butler-example-eureka
server.port=11001
eureka.client.service-url.defaultZone=http://eureka.didispace.com/eureka/

Specific examples of the code visible swagger-butler-example-eureka directory

Integration with the consul

When integrated eureka get all API documentation at the registration center, only need to add the following configuration on the basis of the above works:

The first step : pom.xml increased consul dependence, such as:

<dependencies>
 <dependency>
 <groupId>com.didispace</groupId>
 <artifactId>swagger-butler-core</artifactId>
 <version>1.0.0</version>
 </dependency>
 <dependency>
 <groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-starter-consul-discovery</artifactId>
 <version>1.3.2.RELEASE</version>
 </dependency>
</dependencies>

Step : Main Class increased @EnableDiscoveryClient, such as:

@EnableDiscoveryClient
@EnableSwaggerButler
@SpringBootApplication
public class EurekaApplication {
 public static void main(String[] args) {
 SpringApplication.run(EurekaApplication.class);
 }
}

The third step : the configuration file to increase eureka configuration, such as:

spring.application.name=swagger-butler-example-consul
server.port=11002
spring.cloud.consul.host=localhost
spring.cloud.consul.port=8500

Specific examples of the code visible swagger-butler-example-consul directory

Published 144 original articles · won praise 43 · Views 1.32 million +

Guess you like

Origin blog.csdn.net/qq_25889465/article/details/104084376