在 Linux 下调试 Swagger(OpenAPI),通常分为几种场景:调试 Swagger UI、调试 后端接口、以及调试 Swagger 文档生成。下面按常见情况给你一套实用方法。
先明确是哪一种:
假设你是 Spring Boot:
curl http://localhost:8080/swagger-ui.html
或 OpenAPI 3:
curl http://localhost:8080/swagger-ui/index.html
如果返回 404:
Swagger UI 本质只是渲染 JSON:
curl http://localhost:8080/v2/api-docs
# 或
curl http://localhost:8080/v3/api-docs
如果能看到 JSON,说明后端 OK,问题在 UI。
Linux 下实时看日志:
tail -f logs/app.log
重点看:
不依赖 Swagger UI:
curl -X GET "http://localhost:8080/api/user/1" \
-H "Authorization: Bearer xxx"
pip install httpie
http GET http://localhost:8080/api/user/1
@Operation(summary = "获取用户")
@GetMapping("/user/{id}")
public User getUser(@Parameter(description="用户ID") @PathVariable Long id)
常见问题:
@RestController@Hidden 隐藏@Schemanetstat -tunlp | grep 8080
# 或
ss -tunlp | grep 8080
iptables -L
# 或
ufw status
如果是 Docker:
docker logs 容器名
docker exec -it 容器名 sh
curl localhost:8080/v3/api-docs
Linux 可直接用:
docker run -p 8081:8080 swaggerapi/swagger-editor
浏览器打开:
http://localhost:8081
/v3/api-docs如果你愿意,可以告诉我:
我可以直接帮你定位。