title: Get detailed error messages from AWS API Gateway Request Validator
body: <h2>Background</h2>
  
  <p>I have an API Gateway created using Swagger 2.0 definitions with <a href="http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-gateway-responses.html" rel="noreferrer">API Gateway extensions</a>.</p>
  
  <p>I overrode the default API Gateway responses, for instance:</p>
  
  <pre><code>x-amazon-apigateway-gateway-responses:
    BAD_REQUEST_BODY:
      statusCode: 400
      responseTemplates:
        application/json: |
          {
            "error": {
              "code": 400,
              "stage": "$context.stage",
              "request": "$context.requestId",
              "message": "$context.error.message"
            }
          }
  </code></pre>
  
  <p>The <code>$context</code> in the above payload comes from <a href="http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference" rel="noreferrer">API Gateway variables</a>.</p>
  
  <p>A sample resource/method in my API looks like this (always <code>LAMBDA_PROXY</code> integrations):</p>
  
  <pre><code>paths:
    /test:
      post:
        parameters:
          - in: body
            name: Test
            required: true
            schema:
            $ref: "#/definitions/Test"
        responses:
          201:
            description: Created
          400:
            description: Bad Request
          401:
            description: Unauthorized
          403:
            description: Forbidden
        x-amazon-apigateway-integration:
        uri: &gt;-
          arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/${lambda}/invocations
        type: aws_proxy
        httpMethod: POST
        credentials: "${credentials}"
        passthroughBehavior: never
  </code></pre>
  
  <p>With the corresponding request payload definition:</p>
  
  <pre><code>definitions:
    Test:
      type: object
      title: Test
      required:
        - date
      properties:
        date:
          type: string
          pattern: "^20[0-9]{2}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$"
          description: Date in YYYY-MM-DD Format
  </code></pre>
  
  <p>And the <a href="http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-request-validator.html" rel="noreferrer">request validator extensions</a>:</p>
  
  <pre><code>x-amazon-apigateway-request-validator: body
  x-amazon-apigateway-request-validators:
    body:
      validateRequestBody: true
      validateRequestParameters: false
  </code></pre>
  
  <h2>Problem</h2>
  
  <p>When I call this endpoint with a missing or invalid <code>date</code>, I always get the same response:</p>
  
  <pre><code>{
      "error": {
          "code": 400,
          "stage": "latest",
          "request": "6b7a64f5-e7f0-11e7-845b-f53ceb4cb049",
          "message": "Invalid request body"
      }
  }
  </code></pre>
  
  <p>However, when I test it through the API Gateway console without the <code>date</code> property:</p>
  
  <pre><code>Request body does not match model schema for content type application/json: [
    object has missing required properties (["date"])
  ]
  </code></pre>
  
  <p>And with an invalid <code>date</code>:</p>
  
  <pre><code>Request body does not match model schema for content type application/json: [
    ECMA 262 regex "^20[0-9]{2}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$" does not match input string "2017/12/25"
  ]
  </code></pre>
  
  <h2>Question</h2>
  
  <p>How can I access the detailed error message so that I can enrich my error response with a more descriptive message than <code>Invalid request body</code>? I suspect that this must be possible, perhaps using <a href="http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-gateway-responses.html" rel="noreferrer"><code>x-amazon-apigateway-gateway-responses</code></a> mapping, but so far I haven't been able to do it.</p>