Amazon web services 我怎样才能过滤有效负载中不受欢迎的额外字段?
我在lambda前面有一个awsapi网关,将数据插入DynamoDB表。 API的PUT方法必须只允许修改某些字段 问题是,如果我在有效负载中提供一些额外的不需要的字段,它们将包含在请求中并更新表。 我希望在API网关级别实现过滤器,而不是lambda(因此它可以保持通用性) 注意:招摇过市正在工作,如果缺少一些字段,则在测试时,我会从API网关收到一个“无效请求正文”响应 下面是我的DynamoDB表中的所有字段:id、firstname、lastname、email、address PUT方法不能修改字段“地址” 因此,我没有将字段“address”放在虚张声势中,我希望API网关拒绝插入,例如:Amazon web services 我怎样才能过滤有效负载中不受欢迎的额外字段?,amazon-web-services,swagger,aws-api-gateway,openapi,Amazon Web Services,Swagger,Aws Api Gateway,Openapi,我在lambda前面有一个awsapi网关,将数据插入DynamoDB表。 API的PUT方法必须只允许修改某些字段 问题是,如果我在有效负载中提供一些额外的不需要的字段,它们将包含在请求中并更新表。 我希望在API网关级别实现过滤器,而不是lambda(因此它可以保持通用性) 注意:招摇过市正在工作,如果缺少一些字段,则在测试时,我会从API网关收到一个“无效请求正文”响应 下面是我的DynamoDB表中的所有字段:id、firstname、lastname、email、address PUT
{
"id" : "123",
"firstname": "John",
"lastname": "Doe",
"email": "john.die@email.com",
"address": "5 awesome avenue"
}
但它被接受并更新表
以下是我的招摇过市/openapi:
{
"openapi": "3.0.1",
"info": {
"version": "2020.09.29",
"title": "${api-name}"
},
"paths": {
"/api/v1/people/{id}": {
"put": {
"responses": {
"200": {
"content": {
"application/json": {
"$ref": "#/components/schemas/GetDetailModel"
}
}
}
},
"parameters": [
{
"name": "x-api-key",
"in": "header",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RequestBodyModel"
}
}
}
},
"security": [
{
"api_key": []
}
],
"x-amazon-apigateway-request-validator": "ValidateAll",
"x-amazon-apigateway-integration": {
"uri": "${put-api}",
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"type": "aws_proxy"
}
}
}
},
"components": {
"schemas": {
"RequestBodyModel": {
"required": ["id","firstname","lastname","email"],
"type": "object",
"properties": {
"id" : {"type": "integer"},
"firstname": {"type": "string"},
"lastname": {"type": "string"},
"email": {"type": "string"}
}
},
"GetDetailModel": {
"type": "object",
"properties": {
"id" : {"type": "integer"},
"firstname": {"type": "string"},
"lastname": {"type": "string"},
"email": {"type": "string"}
}
}
},
"securitySchemes": {
"api_key": {
"type": "apiKey",
"name": "x-api-key",
"in": "header"
}
}
},
"x-amazon-apigateway-request-validators": {
"Validate body": {
"validateRequestParameters": false,
"validateRequestBody": true
},
"NoValidation": {
"validateRequestParameters": false,
"validateRequestBody": false
},
"ValidateAll": {
"validateRequestParameters": true,
"validateRequestBody": true
}
}
}
我还尝试在“body”中使用“RequestBodyModel”参数,结果相同:
{
"openapi": "3.0.1",
"info": {
"version": "2020.09.29",
"title": "${api-name}"
},
"paths": {
"/api/v1/people/{id}": {
"put": {
"responses": {
"200": {
"content": {
"application/json": {
"$ref": "#/components/schemas/GetDetailModel"
}
}
}
},
"parameters": [
{
"name": "x-api-key",
"in": "header",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer"
}
},
{
"in": "body",
"name": "RequestBodyModel",
"required": true,
"schema": {
"$ref": "#/components/schemas/RequestBodyModel"
}
}
],
"security": [
{
"api_key": []
}
],
"x-amazon-apigateway-request-validator": "ValidateAll",
"x-amazon-apigateway-integration": {
"uri": "${put-api}",
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"type": "aws_proxy"
}
}
}
},
"components": {
"schemas": {
"RequestBodyModel": {
"required": ["id","firstname","lastname","email"],
"type": "object",
"properties": {
"id" : {"type": "integer"},
"firstname": {"type": "string"},
"lastname": {"type": "string"},
"email": {"type": "string"}
}
},
"GetDetailModel": {
"type": "object",
"properties": {
"id" : {"type": "integer"},
"firstname": {"type": "string"},
"lastname": {"type": "string"},
"email": {"type": "string"}
}
}
},
"securitySchemes": {
"api_key": {
"type": "apiKey",
"name": "x-api-key",
"in": "header"
}
}
},
"x-amazon-apigateway-request-validators": {
"Validate body": {
"validateRequestParameters": false,
"validateRequestBody": true
},
"NoValidation": {
"validateRequestParameters": false,
"validateRequestBody": false
},
"ValidateAll": {
"validateRequestParameters": true,
"validateRequestBody": true
}
}
}
谢谢你的帮助