'AWS API Gateway schema validation with custom formats
Can I use my own custom formats in my OpenAPI definition and have the AWS API Gateway validate using them? I can't find any reference for this so I assume not?
For example, I would only like to greet guys named Dave:
swagger: "2.0"
info:
version: "1.0"
title: "Hello World API"
paths:
/hello/{user}:
get:
description: Returns a greeting to the user!
parameters:
- name: user
in: path
type: string
required: true
description: The name of the user to greet.
format: "guys-named-dave"
Solution 1:[1]
The documentation on this is a bit implicit, indeed. If you combine this
with this
https://swagger.io/specification/#schema-object
the following should be a solution, that works (and it does!)
paths:
/hello
get:
x-amazon-apigateway-request-validator: params
parameters:
- name: user
in: path
required: true
schema:
type: string
pattern: ^.*dave.*$
x-amazon-apigateway-request-validators:
params:
validateRequestParameters: true
To allow for case insensitive names like "Dave" and "DAVE", try the pattern /.*dave.*/i. I don't know if this will work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | donbunkito |
