1

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"
Helen
  • 87,344
  • 17
  • 243
  • 314
dx123908
  • 11
  • 2

1 Answers1

-1

The documentation on this is a bit implicit, indeed. If you combine this

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-request-validation-set-up.html

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.

donbunkito
  • 488
  • 5
  • 9