API网关中的“导出为Swagger”和“导出为Swagger + Postman”缺少“参数”对象

时间:2018-08-08 20:49:00

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

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

{
  "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定义时,导出的定义缺少'parameters'对象,从而使其成为不完整的swagger文件。当我

时,我也遇到过同样的问题
  1. 尝试从用户界面中导出,如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"
            }
          }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

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