温馨提示×

Ubuntu Swagger的文档在哪里找

小樊
34
2025-12-29 21:57:45
栏目: 智能运维

Ubuntu 上 Swagger 文档的查找与访问

常见定位方式

  • 本地运行的 Swagger UI:默认页面通常是 http://localhost:8080http://localhost:3000;若集成到应用,常见路径为 /api-docs/swagger-ui.html。例如,使用 swaggerapi/swagger-ui-express 时访问 http://localhost:8080;使用 swagger-ui-express 挂载到 /api-docs 时访问 http://localhost:3000/api-docs;Spring Boot 项目常见 http://localhost:8080/swagger-ui.html
  • 服务器部署:若通过 Nginx/Apache 或容器发布,需使用服务器地址(域名或 IP)替换 localhost,如 http://your-domain.com/swagger-ui.htmlhttp://服务器IP:端口/swagger-ui.html
  • 在线查看与编辑:可直接使用 Swagger Editor 在线 Live Demo 打开并导入 swagger.yaml/swagger.json 查看与编辑。

快速自检步骤

  • 确认服务是否在运行:检查进程或端口占用,例如 ps aux | grep swaggerss -tlnp | grep ‘:8080|:3000’;若通过 Docker 启动,使用 docker ps 查看容器是否在运行。
  • 核对访问地址与路径:确保使用正确的 协议(http/https)主机(localhost/服务器IP/域名)端口上下文路径(/、/api-docs、/swagger-ui.html)
  • 容器端口映射:若使用 Docker,确认启动命令包含 -p 8080:8080-p 3000:3000,否则主机无法访问容器端口。
  • 文件与路由是否正确:确认 swagger.yaml/swagger.json 路径正确,且应用已将其通过 Swagger UI 正确挂载到可访问路径。

常见安装与访问对照

方式 启动命令或路径 默认访问地址
Docker(swaggerapi/swagger-ui-express) docker run -p 8080:8080 swaggerapi/swagger-ui-express http://localhost:8080
Node.js + swagger-ui-express app.use(‘/api-docs’, swaggerUi.serve, swaggerUi.setup(doc)); http://localhost:3000/api-docs
本机 Swagger Editor git clone … && npm start http://localhost:8080
Spring Boot(springfox) 启动应用后内置页面 http://localhost:8080/swagger-ui.html
Nginx 反向代理示例 将 /swagger-ui.html 代理到 8080 http://your-domain.com/swagger-ui.html
以上地址与路径为常见默认值,具体以你的项目配置为准。

0