1

The newly released "x-amazon-apigateway-request-validator" (in April I believe) is supposed to be able to run a JSON schema validation against the POST/PUT payload of an API.

I've tried to implement this in several different ways now but I can't make it work... I have added the validators:

"x-amazon-apigateway-request-validators": {
  "ValidateBody": {
    "validateRequestParameters": false,
    "validateRequestBody": true
  },
  "ValidateHeaders": {
    "validateRequestParameters": true,
    "validateRequestBody": false
  }

}

For any methind I will look for specific headers so I also have the parameters in the "root" of the Swagger:

"x-amazon-apigateway-request-validator": "ValidateHeaders"

In the POST I have a x-amazon-apigateway-request-validator: ValidateBody and then a Model with the JSON schema where several elements are required.

I can however POST anything as long as it is JSON... There is no validation against the JSON schema done...

What am I missing?

Anders
  • 3,198
  • 1
  • 20
  • 43
  • This is the guide I have followed: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-request-validation.html – Anders May 18 '17 at 15:23

1 Answers1

2

It is working! There is a time lag between the deploy and the actual usage of the new code even though I am not doing any caching it seems.

Went out for lunch and came back to a working solution!

{
  "message": "Invalid request body"
}

It would be nice to be able to modify the response message though...

Anders
  • 3,198
  • 1
  • 20
  • 43
  • Hi Anders, I am facing the same issue. I'm wondering if it is impossible to customize this response message? – tianz Nov 29 '17 at 22:27
  • Yes, if you check under "Gateway Responses" you'll find `Bad Request Body (400)` where you can alter the message – Anders Nov 30 '17 at 10:33
  • @Anders I asked something related in https://stackoverflow.com/q/47953570/89771, do you happen to know the solution by any chance? – Alix Axel Dec 23 '17 at 15:36