【发布时间】:2018-02-01 13:16:16
【问题描述】:
我已将我的 AWS APIGateway 配置为根据 JSON 架构验证请求。
例如路径 /vehicle,附有以下架构:
{
"type":"object",
"properties":{
"licensePlate":{
"pattern":"[A-Za-z]{1,3} [A-Za-z]{1,2} \\d{1,4}",
"type":"string"
},
"vehicleType":{
"type":"string",
"enum":[
"Truck",
"Trailer"
]
}
},
"required":[
"licensePlate",
"vehicleType"
]
}
这很好用。如果我提交无效请求,API 会以 400 {"message": "Invalid request body"} 响应。我想自定义此消息,例如到
{
"entity": "vehicleType",
"message": "missing"
}
如果我查看来自网关的日志,似乎记录了类似的消息 (object has missing required properties (["vehicleType"]))。我可以用那个吗?如何访问它?
日志:
Execution log for request test-request
Thu Feb 01 13:12:18 UTC 2018 : Starting execution for request: test-invoke-request
Thu Feb 01 13:12:18 UTC 2018 : HTTP Method: POST, Resource Path: /vehicle
Thu Feb 01 13:12:18 UTC 2018 : Method request path: {}
Thu Feb 01 13:12:18 UTC 2018 : Method request query string: {}
Thu Feb 01 13:12:18 UTC 2018 : Method request headers: {}
Thu Feb 01 13:12:18 UTC 2018 : Method request body before transformations: {
"licensePlate": "HH AB 123"
}
Thu Feb 01 13:12:18 UTC 2018 : Request body does not match model schema for content type application/json: [object has missing required properties (["vehicleType"])]
Thu Feb 01 13:12:18 UTC 2018 : Method completed with status: 400
API 网关可以做到这一点吗?
【问题讨论】:
-
您找到获取这些消息的方法了吗?
标签: amazon-web-services validation aws-api-gateway