skip to Main Content

In AWS API Gateway, I have a model like this:

{
  "required" : [ "validUntil" ],
  "type" : "object",
  "properties" : {
    "validUntil" : {
      "$ref":"https://apigateway.amazonaws.com/restapis/xxxyyyzzz/models/Timestamp"
    },
    "deadline" : {
      "$ref":"https://apigateway.amazonaws.com/restapis/xxxyyyzzz/models/Date"
    }
  }
}

When I pass a request with invalid timestamp, e.g. 2023-12-32T00:00:00+00:00, i.e. December the 32nd, I get error as expected:

Gateway response body: {"errorCode":"BAD_REQUEST_BODY","message":"Invalid request body","description":"[format attribute "date" not supported, string "2023-12-32T00:00:00+00:00" is invalid against requested date format(s) [yyyy-MM-dd'T'HH:mm:ssZ, yyyy-MM-dd'T'HH:mm:ss.SSSZ]]"}

That works fine.

Yet… when I pass 2023-12-32 as deadline which uses Date model then the request is valid:

Request validation succeeded for content type application/json

Why is that? Why API Gateway doesn’t trigger error?

Here are my models:

Date:

{
  "type" : "string",
  "description" : "Date in ISO 8601 format.",
  "format" : "date"
}

Timestamp

{
  "type" : "string",
  "description" : "Timestamp as defined by ISO 8601 with time offset.",
  "format" : "date-time"
}

JSON Schema specification: https://json-schema.org/understanding-json-schema/reference/string.html#dates-and-times

2

Answers


  1. Chosen as BEST ANSWER

    From API Gateway documentation (in June 2023): https://docs.aws.amazon.com/apigateway/latest/developerguide/models-mappings-models.html

    In API Gateway, models are defined using the JSON schema draft 4

    Linked JSON Schema spec with date format is from draft 7

    enter image description here

    Thus, as API Gateway is using older specification, it doesn't validate date format as assumed.


  2. The section of the JSON Schema spec which you linked to states that the date type is new in draft 7, whereas the date-time type has been around for a longer time.

    enter image description here

    The AWS API gateway uses an old version of the JSON Schema spec, so it does not understand the date type.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search