Linux下Swagger实现API文档共享的实用方案
一 方案总览
二 方案一 Docker快速部署Editor与UI
docker pull swaggerapi/swagger-editor:v4.6.0
docker run -d -p 38080:8080 swaggerapi/swagger-editor:v4.6.0
docker pull swaggerapi/swagger-ui:v4.15.5
docker run -d -p 38081:8080 swaggerapi/swagger-ui:v4.15.5
docker cp ./swagger.json <容器ID>:/usr/share/nginx/html/swagger.json
三 方案二 集成到Spring Boot并共享
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.path=/swagger-ui
<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>
四 方案三 微服务统一入口与远程共享
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
sudo systemctl enable --now cpolar
五 安全与运维建议