在Linux系統下使用Postman生成API文檔,可以按照以下步驟進行:
Postman本身不直接支持將JSON轉換為HTML或Markdown,但你可以使用第三方工具如docgen
來實現這一功能。
# 安裝docgen
wget https://raw.githubusercontent.com/thedevsaddam/docgen/v3/install.sh -o install.sh && sudo chmod +x install.sh && sudo ./install.sh && rm install.sh
# 從Postman導出為JSON文件
docgen server -f ~/Downloads/Api_Test_postman_collection.json -p 8000
# 查看實時在線HTML文檔
docgen server -f ~/Downloads/Api_Test_postman_collection.json -p 8000
# 生成本地HTML文檔
docgen build -i ~/Downloads/Api_Test_postman_collection.json -o ~/Downloads/Api_Test_postman_collection.html
# 生成本地Markdown文檔
docgen build -i ~/Downloads/Api_Test_postman_collection.json -o ~/Downloads/Api_Test_postman_collection.md -m
如果你更喜歡使用命令行,可以安裝Postman命令行工具,然后使用newman
來生成和發布文檔。
# 安裝必要的依賴
sudo apt-get install libgconf-2-4
# 下載Postman CLI工具
wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz
# 解壓到/opt目錄
sudo tar -xzf postman.tar.gz -C /opt
# 創建軟鏈接
sudo ln -s /opt/Postman/Postman /usr/bin/postman
# 使用newman生成HTML文檔
newman run /path/to/postman_collection.json -e /path/to/postman_environment.json -o /path/to/output.html
通過以上步驟,你可以在Linux系統下使用Postman生成和管理API文檔,從而提高API的可讀性和可維護性,促進團隊間的協作和溝通。