【问题标题】:can we generate automatic documentation from api gateway我们可以从 api 网关生成自动文档吗
【发布时间】:2022-03-12 09:21:12
【问题描述】:

我正在将 Lambda API 网关 REST API 与无服务器一起使用。我想生成自动 API 文档,而不是在开放 API 中手动编写。我从亚马逊看到了这个文档 https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-export-api.html

当我使用它时,它没有正确生成响应。它会生成这样的东西

responses:
    200:
      description: "200 response"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Empty"

我想知道我是否做错了什么,或者是否有任何其他方法可以为无服务器 API 网关生成文档。

提前致谢。

【问题讨论】:

    标签: amazon-web-services api aws-lambda aws-api-gateway serverless


    【解决方案1】:

    您的响应似乎没有建模。例如,以下是使用 SAM 框架的方法:

    https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-api.html#sam-api-gatewayresponses

    导出从您的 api 生成一个 openapi 或 swagger 定义。然后。您可以使用 openapi-generator-cli 生成文档(以及客户端库和其他好东西)

    例如:

    aws apigateway get-export --parameters extensions='apigateway' --rest-api-id abcdefg123 --stage-name dev --export-type oas30 openapi.yaml
    

    然后

    openapi-generator-cli generate -i openapi.yaml -g html -o doc
    

    在此处查看更多文档示例:

    https://openapi-generator.tech/docs/generators#documentation-generators

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 1970-01-01
      • 2020-06-09
      • 2012-04-07
      • 1970-01-01
      • 2022-01-16
      相关资源
      最近更新 更多