如何正确地将MethodResponse应用于“过滤” AWS api网关响应

时间:2019-08-12 09:18:46

标签: amazon-web-services amazon-cloudformation aws-api-gateway

当尝试应用MethodResponse模板时,我看不到最终响应的任何差异。我的目标是为数组属性成功应用带有minItems和maxItems的架构。

lambda方法的示例响应:

{
  "_id": "5d5110f52e8b560af82dec69",
  "index": 0,
  "friends": [
    {
      "id": 0,
      "name": "Mcconnell Pugh"
    },
    {
      "id": 1,
      "name": "Peggy Caldwell"
    },
    {
      "id": 2,
      "name": "Jocelyn Mccarthy"
    }
  ]
}

我尝试在MethodResponse中应用的模式:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title" : "Empty Schema",
  "type" : "object",
  "properties" : {
    "friends" : {
        "type" : "array",
        "minItems" : 1,
        "maxItems" : 2,
        "items" : {
            "type" : "object",
            "properties" : {
                "name" : {
                    "type" : "string"
                },
                "id": {
                    "type" : "integer"
                }
            }
        }
    },
    "index" : {
        "type" : "string"
    }
  }
}

我希望最终答复中只会看到两个“朋友”,而不是全部。

1 个答案:

答案 0 :(得分:0)

经过长期研究和大量AWS文档,我发现:

  1. 它支持JSON模式4,但是不支持所有功能->相关的docs

  2. 方法响应基本上不应用验证。据我了解,如果您想将您的API导出到Swagger以得到详细描述的规范,它会带来用处->相关的docs最后一段很重要

因此,我的问题的最终答案是-您不能将“方法响应”用作过滤器,这不是它的目的。