constswaggerDocument=require('./swagger.json');// some swagger documentconstswagger2Validator=requrie('ut-swagger2-validator');constvalidators=swagger2Validator(swaggerDocument);// some operationId corresponding to a given swagger document routeconstoperationId='namespace.entity.action';constvalidator=validators[operationId];if(!validator){// there is no validator matching the given operationId}// Note: 'pathParameters' might not be provided if 'path' is// provided and vice versaconstrequestValidationErrors=awaitvalidator.request({
query,
body,
files,
headers,
pathParameters,
path
});if(requestValidationErrors.length>0){// there are request validation errors}constresponseValidationErrors=awaitvalidator.response({status, body});if(responseValidationErrors.length>0){// there are response validation errors}