Amanda Ferrari
Amanda Ferrari

Reputation: 946

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.

Upvotes: 3

Views: 1563

Answers (1)

Kashyap
Kashyap

Reputation: 17411

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.

Upvotes: 5

Related Questions