在 Debian 系统中集成 Swagger(通常指 Swagger UI / OpenAPI),主要取决于你使用的后端语言/框架。下面我按常见场景给你一个清晰、可操作的说明。
Swagger 本身不是服务,而是:
Debian 只是运行环境(Linux),集成方式和 Ubuntu 基本一致。
springdoc-openapi推荐,替代旧的 springfox
步骤:
sudo apt update
sudo apt install openjdk-17-jdk maven -y
pom.xml 添加依赖:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version>
</dependency>
访问地址:
http://localhost:8080/swagger-ui.html
pip install fastapi uvicorn
访问:
http://localhost:8000/docs
pip install flasgger
from flasgger import Swagger
Swagger(app)
访问:
http://localhost:5000/apidocs
go install github.com/swaggo/swag/cmd/swag@latest
swag init
引入:
github.com/swaggo/gin-swagger
访问:
http://localhost:8080/swagger/index.html
适合:已有 openapi.yaml/json
sudo apt install nginx -y
git clone https://github.com/swagger-api/swagger-ui.git
cp -r swagger-ui/dist /var/www/swagger
Nginx 配置:
server {
listen 80;
root /var/www/swagger;
index index.html;
}
修改 swagger-initializer.js 指向你的 API 文档。
systemctl enable nginx
systemctl start nginx
或用 Docker(更推荐):
docker run -p 8080:8080 swaggerapi/swagger-ui
可以告诉我:
我可以直接给你完整配置文件 + 示例。