在 Linux 环境下,Swagger 并不是 Linux 特有的东西,而是一个用于描述、生成、调试和可视化 RESTful API 的开放工具生态。可以从以下几个层面理解:
Swagger 是一套围绕 OpenAPI 规范(OAS) 的工具集合,主要解决:
常见组件:
在 Linux 服务器或开发环境中,“swagger”一般出现在以下场景:
如 Java(Spring Boot)、Go、Python(FastAPI)等在 Linux 上运行:
http://服务器IP:端口/swagger-ui.html
用于查看和测试接口。
Linux 中常见命令工具:
swagger init spec
swagger validate api.yaml
swagger serve api.yaml
或使用:
npm install -g @redocly/cli
redocly lint openapi.yaml
Docker 中运行 Swagger UI:
docker run -p 8080:8080 swaggerapi/swagger-ui
# 安装
pip install fastapi uvicorn
# main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/hello")
def hello():
return {"msg": "hi"}
启动后访问:
http://localhost:8000/docs
这就是 Swagger UI。
如果你是指:
可以直接告诉我你的使用场景。