在 Debian 上“导出 Swagger”通常指把 Swagger/OpenAPI 文档(JSON 或 YAML)导出来,或者把接口定义生成代码/离线文档。下面按常见场景说明。
大多数 Swagger 项目会提供:
http://IP:端口/v2/api-docshttp://IP:端口/v2/api-docs.yaml例如:
curl http://localhost:8080/v2/api-docs -o swagger.json
curl http://localhost:8080/v2/api-docs.yaml -o swagger.yaml
如果是 Swagger UI:
http://IP:端口/swagger-ui.html
/v2/api-docs
/v3/api-docs
/v3/api-docs.yaml
导出示例:
curl http://localhost:8080/v3/api-docs -o openapi.json
wget / curlsudo apt update
sudo apt install curl wget -y
npm install -g swagger-cli
swagger-cli validate swagger.yaml
swagger-cli bundle swagger.yaml -o swagger.json
swagger-ui 静态导出git clone https://github.com/swagger-api/swagger-ui.git
cp swagger.json swagger-ui/dist/
# 修改 index.html 指向 swagger.json
redocnpm install -g redoc-cli
redoc-cli build swagger.yaml -o api.html
apt install wkhtmltopdf
wkhtmltopdf api.html api.pdf
如果是 Java 项目:
mvn springfox-swagger2:generate
或在代码中启用:
@EnableSwagger2
如果你能告诉我:
我可以给你精确到命令的示例。