express-zod-openapi
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -455,6 +455,7 @@ require('zod'); | ||
function setupResponseValidation(res, specInfo, segmentOrder) { | ||
function setupResponseValidation(res, specInfo, segmentOrder, next) { | ||
const originalSend = res.send; | ||
res.send = function validateAndSendResponse(...args) { | ||
res.send = originalSend; | ||
const body = args[0]; | ||
@@ -469,3 +470,4 @@ const isJsonContent = /application\/json/.test(String(res.get('content-type'))); | ||
if (!schemaBySegment) { | ||
throw new Error(`Validation Schema not found for Response(${res.statusCode})`); | ||
next(new Error(`Validation Schema not found for Response(${res.statusCode})`)); | ||
return res; | ||
} | ||
@@ -483,3 +485,4 @@ | ||
if (!result.success) { | ||
throw new ResponseValidationError(result.error, segment); | ||
next(new ResponseValidationError(result.error, segment)); | ||
return res; | ||
} | ||
@@ -541,3 +544,3 @@ | ||
if (!skipResponseValidation && validationSchema.res) { | ||
setupResponseValidation(res, specInfo, resSegmentOrder); | ||
setupResponseValidation(res, specInfo, resSegmentOrder, next); | ||
} | ||
@@ -550,2 +553,3 @@ | ||
next(err); | ||
return; | ||
} | ||
@@ -552,0 +556,0 @@ } |
@@ -455,6 +455,7 @@ import 'zod'; | ||
function setupResponseValidation(res, specInfo, segmentOrder) { | ||
function setupResponseValidation(res, specInfo, segmentOrder, next) { | ||
const originalSend = res.send; | ||
res.send = function validateAndSendResponse(...args) { | ||
res.send = originalSend; | ||
const body = args[0]; | ||
@@ -469,3 +470,4 @@ const isJsonContent = /application\/json/.test(String(res.get('content-type'))); | ||
if (!schemaBySegment) { | ||
throw new Error(`Validation Schema not found for Response(${res.statusCode})`); | ||
next(new Error(`Validation Schema not found for Response(${res.statusCode})`)); | ||
return res; | ||
} | ||
@@ -483,3 +485,4 @@ | ||
if (!result.success) { | ||
throw new ResponseValidationError(result.error, segment); | ||
next(new ResponseValidationError(result.error, segment)); | ||
return res; | ||
} | ||
@@ -541,3 +544,3 @@ | ||
if (!skipResponseValidation && validationSchema.res) { | ||
setupResponseValidation(res, specInfo, resSegmentOrder); | ||
setupResponseValidation(res, specInfo, resSegmentOrder, next); | ||
} | ||
@@ -550,2 +553,3 @@ | ||
next(err); | ||
return; | ||
} | ||
@@ -552,0 +556,0 @@ } |
{ | ||
"name": "express-zod-openapi", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Express Zod OpenAPI", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
556255
1364