@@ -3,9 +3,10 @@ import path from 'path';
33import _ from 'lodash' ;
44import * as OpenApiValidator from 'express-openapi-validator' ;
55import { OpenAPIFramework } from 'express-openapi-validator/dist/framework/index' ;
6- import type { Handler } from 'express' ;
6+ import type { Handler , Request } from 'express' ;
77
88import type { AnyServiceLocals , ServiceExpress , ServiceLocals } from './types' ;
9+ import { getNodeEnv } from './env' ;
910import { getFilesInDir , loadModule } from './express-app/modules' ;
1011import { ConfigurationSchema } from './config/schema' ;
1112
@@ -116,6 +117,19 @@ export async function openApi<
116117
117118 const { routing } = app . locals . config ;
118119 const combinedOptions = {
120+ // In test mode, validate returned swagger responses. This can easily be disabled
121+ // by setting validateResponses to false in the config.
122+ ...( getNodeEnv ( ) === 'test'
123+ ? {
124+ validateResponses : {
125+ onError ( error : Error , body : unknown , req : Request ) {
126+ console . log ( 'Response body fails validation: ' , error ) ;
127+ console . log ( 'Emitted from:' , req . originalUrl ) ;
128+ console . debug ( body ) ;
129+ } ,
130+ } ,
131+ }
132+ : { } ) ,
119133 ...( typeof routing . openapi === 'object' ? routing . openapi : { } ) ,
120134 ...openApiOptions ,
121135 } ;
0 commit comments