Search code examples
aws-api-gateway

AWS API Gateway request validation - supported types and formats


I have been experimenting with AWS API Gateway and request validation according to OpenAPI Specification (see https://swagger.io/docs/specification/data-models/data-types/#:~:text=OpenAPI%20defines%20the%20following%20built,07%2D21T17%3A32%3A28Z)

It seems that AWS does not conform to specification, at least for date format. When I try model with

{
  "date": {
        "type": "string",
        "format": "date-time"
  }
}

then it seems that API Gateway does not validate content at all (any arbitrary string is allowed).

On the other way date-time works properly as defined in OpenAPI and RFC-3339.

Is there any official documentation or compatibility matrix? I wasn't able to find anything.


Solution

  • AWS API Gateway does support date-time format validation. Just make sure to enable request validation (disabled by default)

    I've tested request with date-time string property in the body:

    • validation disabled: no error when any arbitrary string is passed
    • validation enabled: an error with status 400 is returned with body {"message": "Invalid request body"}, there's a message in the api gateway log that says that request body does not match model schema (log also contains details about the value and requested format).