File tree Expand file tree Collapse file tree 3 files changed +2192
-630
lines changed Expand file tree Collapse file tree 3 files changed +2192
-630
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import Param from './param.js';
33import Ajv from 'ajv' ;
44import addFormats from 'ajv-formats' ;
55import { ValidationError } from 'express-json-validator-middleware' ;
6+ import Generic from '@openaddresses/batch-generic' ;
67
78const ajv = addFormats ( new Ajv ( {
89 allErrors : true ,
@@ -99,6 +100,7 @@ export default class Middleware {
99100
100101 /**
101102 * Express middleware to validate the response body
103+ * and optionally serialize Generic object to JSON
102104 *
103105 * @param {Object } schema JSON Schema
104106 *
@@ -110,6 +112,10 @@ export default class Middleware {
110112 return function ( req , res , next ) {
111113 const json = res . json ;
112114 res . json = function ( obj ) {
115+ if ( obj instanceof Generic && typeof obj . serialize === 'function' ) {
116+ obj = obj . serialize ( ) ;
117+ }
118+
113119 if ( res . statusCode === null || res . statusCode === 200 ) {
114120 validate ( obj ) ;
115121 }
You can’t perform that action at this time.
0 commit comments