在 Debian 上“调试 Swagger 接口”通常分几种场景:看 Swagger UI、用命令行调接口、或本地起服务联调。下面按常见用法给你一份实用指南。
如果你已经有一个提供 Swagger 的服务(如 Spring Boot、FastAPI、Node 等):
java -jar app.jar
http://localhost:8080/swagger-ui.html
或
http://localhost:8080/swagger-ui/index.html
✅ 适合快速验证接口是否正常
即使没有 Swagger UI,也可以直接调接口。
curl -X GET "http://localhost:8080/api/users" \
-H "Authorization: Bearer token"
POST + JSON:
curl -X POST "http://localhost:8080/api/login" \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"123456"}'
查看 Swagger JSON:
curl http://localhost:8080/v3/api-docs
安装:
sudo apt update
sudo apt install httpie
使用:
http GET http://localhost:8080/api/users
http POST http://localhost:8080/api/login username=admin password=123456
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>
访问:
/v3/api-docs
/swagger-ui.html
pip install fastapi uvicorn
自动生成:
/docs
/openapi.json
✅ 看实际请求
curl -v http://localhost:8080/api
✅ 抓包(高级)
sudo apt install tcpdump
sudo tcpdump -i lo port 8080
✅ 日志
application.yml 开 debugaccess.log❌ 跨域 → 后端加 CORS
❌ 404 → 路径或 context-path 错
❌ 401 → token / 权限问题
❌ Debian 防火墙
sudo ufw status
如果你能告诉我:
我可以直接给你“对应场景”的精确步骤。