【问题标题】:"Export as Swagger" and "Export as Swagger + Postman" from API gateway is missing 'parameters' objectAPI 网关的“导出为 Swagger”和“导出为 Swagger + Postman”缺少“参数”对象
【发布时间】:2019-01-16 05:38:16
【问题描述】:

我有一个 API 网关端点 (/item/{itemId}),其中包含路径参数“itemId”。这是我用来在 API 网关中创建端点的 swagger 定义。

{
  "swagger": "2.0",
  "info": {
    "version": "v1",
    "title": "sample-postman-import"
  },
  "host": "example.com",
  "basePath": "/api",
  "schemes": ["https"],
  "paths": {
    "/item/{itemId}": {
      "get": {
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "itemId",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "200 response"
            }
          }
      }
    }
  }

部署 API 后,当我将其导出为 swagger 定义时,导出的定义缺少“参数”对象,使其成为不完整的 swagger 文件。当我遇到同样的问题时

  1. 尝试从 UI 导出,如https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-export-api.html 所示
  2. 使用了来自 javascript aws-sdk https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/APIGateway.html#getExport-property 的 getExport API 调用

这是导出的样子:

{
  "swagger": "2.0",
  "info": {
    "version": "v1",
    "title": "sample-postman-import_old"
  },
  "host": "example.com",
  "basePath": "/api",
  "schemes": ["https"],
  "paths": {
    "/item/{itemId}": {
      "get": {
        "produces": [
          "application/json"
        ],
        "responses": {
          "200": {
            "description": "200 response"
            }
          }
      }
    }
  }
}

【问题讨论】:

    标签: amazon-web-services export postman aws-api-gateway swagger-2.0


    【解决方案1】:

    我在使用 Terraform 创建 API 网关时遇到了同样的问题。在 AWS UI 上显示了参数,但是当我通过 AWS CLI 使用 aws apigateway get-method 命令请求方法信息时,未提供参数。因此,请确保根据需要设置了“requestParameters”,如果没有,请通过 CLI 或 Terraform 进行设置。

    【讨论】:

      猜你喜欢
      • 2017-03-08
      • 2016-12-28
      • 1970-01-01
      • 2021-10-18
      • 2019-12-30
      • 2020-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多