express-openapi-validator
express-openapi-validator copied to clipboard
Error thrown with empty query parameter does not have errorCode
Describe the bug
When a query parameter is empty, the BadRequest error thrown by express-openapi-validator does not contain an errorCode property, whereas other errors do.
To Reproduce
Specify a parameter schema such as:
name: after
description: The after cursor provided by a prior request.
in: query
required: false
schema:
type: string
# mongo id length/pattern
maxLength: 24
minLength: 24
pattern: ^[a-fA-F\d]{24}$
Then make a request like:
GET /foo?after=
Actual behavior
The thrown error has a structure like:
{
name: 'Bad Request',
path: '/query/after',
message: "Empty value found for query parameter 'after'",
errors: [
{
path: '/query/after',
message: "Empty value found for query parameter 'after'"
}
]
}
Expected behavior The thrown error should have an errorCode like:
{
name: 'Bad Request',
path: '/query/after',
message: "Empty value found for query parameter 'after'",
errors: [
{
path: '/query/after',
message: "Empty value found for query parameter 'after'",
errorCode: 'empty.openapi.validation'
}
]
}
Examples and context Snippets provided above.