OpenAPI definitions of a sample API with basic request validation
The following OpenAPI definition defines a sample API with request validation
enabled. The API is a subset of the PetStore
APIPOST
method to add a pet to the
pets
collection and a GET
method to query pets by a
specified type.
There are two request validators declared in the
x-amazon-apigateway-request-validators
map at the API level. The
params-only
validator is enabled on the API and inherited by the
GET
method. This validator allows API Gateway to verify that the required
query parameter (q1
) is included and not blank in the incoming request. The
all
validator is enabled on the POST
method. This
validator verifies that the required header parameter (h1
) is set and not
blank. It also verifies that the payload format adheres to the specified
RequestBodyModel
If there is no matching content type is found, request
validation is not performed. When using a model to validate the body, if no matching content type is found, request
validation is not performed. To use the same model regardless of the content type, specify $default
as the key.
This model requires that the input JSON object contains the name
,
type
, and price
properties. The name
property
can be any string, type
must be one of the specified enumeration fields
(["dog", "cat", "fish"]
), and price
must range between 25
and 500. The id
parameter is not required.