Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services AWS API网关(REST)-即使存在未知属性,请求验证也会通过_Amazon Web Services_Aws Api Gateway_Jsonschema_Openapi_Swagger 2.0 - Fatal编程技术网

Amazon web services AWS API网关(REST)-即使存在未知属性,请求验证也会通过

Amazon web services AWS API网关(REST)-即使存在未知属性,请求验证也会通过,amazon-web-services,aws-api-gateway,jsonschema,openapi,swagger-2.0,Amazon Web Services,Aws Api Gateway,Jsonschema,Openapi,Swagger 2.0,我有一个具有以下架构的API网关: { "swagger": "2.0", "info": { "description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [i

我有一个具有以下架构的API网关:

 {
  "swagger": "2.0",
  "info": {
    "description": "This is a sample server Petstore server.  You can find out more about     Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).      For this sample, you can use the api key `special-key` to test the authorization     filters.",
    "version": "1.0.0",
    "title": "Swagger Petstore",
    "termsOfService": "http://swagger.io/terms/",
    "contact": {
      "email": "apiteam@swagger.io"
    },
    "license": {
      "name": "Apache 2.0",
      "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
    }
  },
  "paths": {
    "/pet": {
      "post": {
        "summary": "Add a new pet to the store",
        "description": "",
        "operationId": "addPet",
        "consumes": [
          "application/json",
          "application/xml"
        ],
        "produces": [
          "application/xml",
          "application/json"
        ],
        "parameters": [
          {
            "in": "body",
            "name": "body",
            "description": "Pet object that needs to be added to the store",
            "required": true,
            "schema": {
              "$ref": "#/definitions/Pet"
            }
          }
        ],
        "responses": {
          "405": {
            "description": "Invalid input"
          }
        }}
}},
  "definitions": {
    "Pet": {
      "required": ["id", "name"],
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "description": "Id of the pet",
          "example": 123
        },
        "name": {
          "type": "string",
          "description": "Name of the pet",
          "example": "Jammy"
        },
        "nickname": {
          "type": "string",
          "description": "Nickname of the pet",
          "example": "Jam"
        }
      }
    }
    
  }
}
当我发送带有模式中不存在的字段的请求正文时,我不会从API网关得到400响应。我已经将配置应用于验证正文、标题和查询字符串


这是API网关中的一个公开问题吗?还是我遗漏了什么?

因此,对于swagger v2和openapiv3规范,默认行为是接受规范未定义的所有附加属性。如果您包含了所需的宠物id和名称以及其他未使用的属性,如foo和bar,那么您的帖子应该会成功


如果您希望更严格的验证在发送其他属性时失败,那么请在您的pet模式中将additionalProperties设置为false,或者这样做,然后将spec版本更改为3.x.x

是否有方法更改此行为?就像使用OpenAPI3.0规范一样?是的,我在上面添加了另一段,其中包含建议的修复程序fyi这实际上是OAS的JSON模式部分=]将additionalProperties设置为false并更改了我的swagger规范版本后,该行为开始起作用。但它不适用于使用allOf的模式。根据,似乎不支持additionalProperties字段。我现在错过了什么?你能用你所有的问题问一个新问题吗?所有组合模式上的additionalProperties都必须省略或为true才能正常工作。additionalProperties仅允许输入当前_schema.properties中未定义的属性。并且当前的_schema.properties不包括所有架构中的属性。