swaggest / rest

Web services with OpenAPI and JSON Schema done quick in Go
https://pkg.go.dev/github.com/swaggest/rest
MIT License
362 stars 17 forks source link

Custom error message is not used for response validation errors #112

Closed pboguslawski closed 1 year ago

pboguslawski commented 1 year ago

Describe the bug

Custom error message struct is not used for response validation errors.

To Reproduce

Try calling /validation API method from advanced example with X-Input = 44; returned error is

{
  "status": "INTERNAL",
  "error": "internal: bad response: validation failed",
  "context": {
    "header:X-Output": [
      "#: must be <= 20/1 but found 44"
    ]
  }
}

Expected behavior Error message should be generated using customErr.

Additional context Input validation errors are formatted as expected:

$ curl --silent -X 'POST' 'http://localhost:8011/validation'  -H 'accept: application/json'  -H 'X-Input: 4'  -H 'Content-Type: application/json'  -d '{ "data": { "value": "string"  } }'| jq
{
  "msg": "invalid argument: validation failed",
  "details": {
    "header:X-Input": [
      "#: must be >= 10/1 but found 4"
    ]
  }
}