/** Errors for an endpoint */ export class EndpointError { request : string [ ] ; response : string [ ] ; } /** Model errors: general errors and endpoint errors */ export class ValidationErrors { generalErrors : string [ ] ; endpointErrors : Record < string , EndpointError > ; constructor ( ) { this . generalErrors = [ ] ; this . endpointErrors = { } ; } /** Add some error information relative to an endpoint's request or response */ addEndpointError ( endpoint , part , message ) { let error = this . endpointErrors [ endpoint ] ; if ( error == null ) { error = { request : [ ] , response : [ ] } ; this . endpointErrors [ endpoint ] = error ; } error [ part ] . push ( message ) ; } /** Add a general error, unrelated to an endpoint */ addGeneralError ( message ) { this . generalErrors . push ( message ) ; } /** Output this error log to the console */ log ( ) { let count = 0 ; const logArray = function ( errs , prefix = '' ) : void { for ( const err of errs ) { if ( err !== 'Missing request & response' ) { console . error ( `${ prefix }${ err }` ) ; count ++ ; } } } ; logArray ( this . generalErrors ) ; const names = Array . from ( Object . keys ( this . endpointErrors ) ) . sort ( ) ; for ( const name of names ) { const endpointErrs = this . endpointErrors [ name ] ; if ( endpointErrs != null ) { for ( const part of [ 'request' , 'response' ] ) { logArray ( endpointErrs [ part ] , `${ name } ${ part }: ` ) ; } } } console . error ( `${ count } errors found.` ) ; } }