【问题标题】:Convert API Gateway Cloudformation template to Swagger file将 API Gateway Cloudformation 模板转换为 Swagger 文件
【发布时间】:2021-03-16 18:56:58
【问题描述】:

Coludformation 模板中描述了一个现有的 API。现在我想使用 Swagger 记录 API。有没有办法解析 Cloudformation 模板以创建 swagger.yaml 规范文件?如果可能,我想避免再次编写 API。

注意:我知道您可以使用 Swagger 定义您的 API,然后在您的 Cloudformation 模板中导入 API 配置。这不是我需要的。 Cloudformation 已经存在并且不会更改。因此,我需要相反的东西:基于现有 Cloudformation 模板的 Swagger 配置文件。

【问题讨论】:

    标签: swagger amazon-cloudformation aws-api-gateway documentation openapi


    【解决方案1】:

    没有办法将模板转换为我知道的 swagger 文件。但是,如果您正在寻找一种仅将服务规范保存在一个地方(模板)并且已部署它的方法,则可以从舞台中获取 swagger 或 OAS 文件(因此,您也必须有一个舞台)至少有两种方式:

    1. 通过 Web 控制台。使用 Amazon API 网关-> APIs->Your API->Stages>Your Stage -> Export 选项卡。看图:exporting Swagger or OAS as a file by Web console

    2. aws apigateway get-export ...这里是一个例子:

    aws apigateway get-export --rest-api-id ${API_ID} --stage-name ${STAGE_NAME} --export-type swagger swagger.json

    【讨论】:

    • 很好,非常感谢您的回答!这就是我一直在寻找的。遗憾的是,我们的 API 网关没有 Swagger 中需要的所有信息(例如错误响应、描述等),因此我必须手动编写 Swagger 规范文件。不过还是谢谢你的回答!
    • 我花了一整天时间尝试将手动添加的方法和模拟导出为招摇模板。阅读大量文档但没有成功,看起来它没有实现。
    猜你喜欢
    • 2018-04-14
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 2018-02-03
    • 2018-11-27
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多