在Linux系统中,Swagger可以通过多种方式与其他工具集成,以下是一些常见的集成方法:
pom.xml
文件中添加Swagger和Springfox的依赖。<!-- Maven -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
.paths(PathSelectors.any())
.build();
}
}
http://localhost:8080/swagger-ui.html
查看和测试API文档。docker pull swaggerapi/swagger-ui:v4.6.0
docker run -d -p 38080:8080 swaggerapi/swagger-ui:v4.6.0
pom.xml
中添加Knife4j依赖。<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
http://localhost:8080/doc.html
访问增强后的Swagger UI。通过上述步骤,您可以在Linux系统中成功集成Swagger与其他工具,从而提高API文档的生成、查看和测试效率。