Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting default values in API Gateway request validation

Is it possible to declare a default value in the model of a api gateway endpoint? I'm trying to, like that:

 1 {
  2   "type": "object",
  3   "required": ["name"],
  4   "properties": {
  5     "name": {
  6       "type": "string",
  7       "default": "My Name"
  8     }
  9   }
 10 }

But it doesn't work at all. If I don't pass the name, the API Gateway will return an error saying that the body is not valid.

Thank you.

like image 257
Amanda Ferrari Avatar asked Jul 21 '26 15:07

Amanda Ferrari


1 Answers

According to AWS docs:

The payload can have a data model according to the JSON schema draft 4.

JSON schema draft 4 doesn't define a way to specify a default value. So my guess is no, it's not possible to do this using an input model.

If you really want to do this in API Gateway layer then perhaps you should explore the input mapping template. "A mapping template is a script expressed in Velocity Template Language (VTL)". VTL seems to have much better capability.

IMHO its a bad idea. I would rather just do this in backend.

like image 67
Kashyap Avatar answered Jul 24 '26 10:07

Kashyap