Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/runtime/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,19 @@ async function validateBody(
logger: CustomLogger
): Promise<unknown> {
const body = req.body
const contentType = (req.headers['content-type'] ?? 'application/json').split(
';'
)[0]
const contentType = (req.headers['content-type'] ?? 'application/json').split(';')[0]

const expectedSchema = rule.content[contentType]?.schema
if (typeof expectedSchema === 'undefined') {
logger.error(`Schema is not found for '${contentType}', throwing error`)
throw new ValidateError({}, 'This content-type is not allowed')
}

if (req.readableEnded === false) {
logger.warn(`! Warning: Body has not be parsed, body validation skipped !`)
logger.debug(`Body has not be parsed, body validation skipped!`)
return body
}

if (discriminatorFn) {
const schemaName = await discriminatorFn(req)
const validationResult = validateAndParseValueAgainstSchema(
Expand Down