在Ubuntu中调试Swagger可按以下步骤操作:
安装基础环境
确保已安装Node.js和npm,若未安装可使用命令:
sudo apt update
sudo apt install -y nodejs npm
安装Swagger工具
npm install -g swagger-editor-cli
npm install -g swagger-ui-express
配置Swagger
index.html
文件,指定本地Swagger规范文件路径(如swagger.yaml
/swagger.json
)。启动调试
npm start
,默认在端口3000运行,可通过浏览器访问http://localhost:3000
。node app.js
,访问http://localhost:3000/api-docs
。接口测试与调试
launch.json
,通过node --inspect-brk app.js
启动调试模式,设置断点查看变量和执行流程。常见问题处理
sudo ufw allow 3000
)。swagger-config.yaml
路径正确,或直接编辑swagger.json
/swagger.yaml
文件。参考来源: