serverless-application-model icon indicating copy to clipboard operation
serverless-application-model copied to clipboard

Use detailed error message when enable API GW request body validation

Open honglu opened this issue 6 years ago • 3 comments

Description: When using API GW's request validation feature to validate request body, by default the error message is Invalid request body without any details on where it is invalid in request body. To get detailed error message, customers have to set the following in their swagger:

x-amazon-apigateway-gateway-responses:
  # Provide more detailed error message for bad request body errors. See doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-gateway-responses.html
  BAD_REQUEST_BODY:
    responseTemplates:
      application/json: '{"message": "$context.error.validationErrorString"}'

It would be nice if SAM can add this to swagger automatically if request body validation is enabled.

honglu avatar Oct 16 '19 01:10 honglu

Thanks for creating the issue, Lu! We don't support adding request-validators in SAM today, but this is on our roadmap. Once that support is added it totally makes sense to add gateway responses for BAD_REQUEST_BODY. It's being tracked in #931

praneetap avatar Oct 18 '19 17:10 praneetap

+1 for this feature

alext234 avatar May 27 '20 08:05 alext234

+1

karthikvadla avatar Aug 05 '20 17:08 karthikvadla