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
From API Gateway documentation (in June 2023): https://docs.aws.amazon.com/apigateway/latest/developerguide/models-mappings-models.html
Linked JSON Schema spec with
date
format is from draft 7Thus, as API Gateway is using older specification, it doesn't validate
date
format as assumed.The section of the JSON Schema spec which you linked to states that the
date
type is new in draft 7, whereas thedate-time
type has been around for a longer time.The AWS API gateway uses an old version of the JSON Schema spec, so it does not understand the
date
type.