在 Debian 上“导出 Swagger”通常指把 Swagger / OpenAPI 文档 导出成 JSON 或 YAML 文件,常见场景有几种,我按常见情况给你说明:
http://localhost:8080/swagger-ui.htmlapi-docs/v2/api-docs(Spring Boot)curl http://localhost:8080/v2/api-docs > swagger.json
或:curl http://localhost:8080/v3/api-docs > openapi.json
✅ 得到 swagger.json 就是导出的 Swagger 文档
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
或(新版本):
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>
# Swagger 2
curl http://localhost:8080/v2/api-docs -o swagger.json
# OpenAPI 3
curl http://localhost:8080/v3/api-docs -o openapi.json
sudo apt update
sudo apt install nodejs npm -y
sudo npm install -g swagger-cli
swagger-cli bundle swagger.json -o exported.yaml
| 格式 | 命令 |
|---|---|
| JSON | curl ... > swagger.json |
| YAML | swagger-cli bundle swagger.json -o swagger.yaml |
| HTML | 用 redoc 或 swagger-ui |
curl http://localhost:8000/openapi.json > openapi.json
curl http://localhost:5000/apispec_1.json > swagger.json
/v2/api-docs 或 /v3/api-docs)如果你能告诉我:
我可以给你一条精确命令。