当 API 网关中不存在密钥时引发 JSON 架构验证错误

Raise JSON Schema Validation Error when key does not exist in API Gateway

尝试访问 AWS 时遇到一些问题 API 网关出错。 提供错误类型时已定义的密钥正确引发验证错误,但如果我向模型中未定义的请求正文添加随机密钥,则 API 网关将继续处理请求并且 returns 200 成功响应。

如何在模型中定义不允许使用随机密钥?

型号

{
  "type" : "object",
  "properties" : {
    "bool" : {
      "type" : "boolean"
    },
    "string" : {
      "type" : "string"
    },
    "int" : {
      "type" : "integer",
      "format" : "int32"
    }
  }
}

请求正文 API GW 正确给出 200 响应

{
    "bool": true,
    "string": "foo",
    "int": 123
}

请求正文无效 API GW 正确给出 400 响应

{
    "bool": "foo",
    "string": 123,
    "int": false
}

请求正文无效 API GW 错误地给出了 200 响应

{
    "bool": true,
    "string": "foo",
    "int": 123,
    "bar":""
}

关于我在 JSON 架构中遗漏的内容有什么想法吗?

我需要将以下内容添加到模型中

"additionalProperties":false

型号

{
  "type" : "object",
  "additionalProperties":false,
  "properties" : {
    "bool" : {
      "type" : "boolean"
    },
    "string" : {
      "type" : "string"
    },
    "int" : {
      "type" : "integer",
      "format" : "int32"
    }
  }
}

来自本期 Only allow properties that are declared in JSON schema