swagger格式转换

开篇

接手一个很老的项目,能够生成swagger1.2的接口文档,通过开源工具转为2.0版本导入公共接口文档仓库

开源工具

  • nodejs安装
  • npm install -g api-spec-converter

使用方式

api-spec-converter --from=swagger_1 --to=swagger_2 --syntax=json --order=alpha swagger1.json > swagger2.json

import os
data = {}  # 项目原1.2格式的文档
for api in data.get("apis"):
    url = "http://127.0.0.1:9999/dosc/api-docs" + api["path"]
    cmd = "api-spec-converter --from=swagger_1 --to=swagger_2 --syntax=json --order=alpha %s > %s.json" % (url, api["path"].split("/")[-1])
    os.popen(cmd)

你可能感兴趣的:(swagger格式转换)