const swaggerDocument = require('./swagger.json'); // some swagger document
const swagger2Validator = requrie('ut-swagger2-validator');
const validators = swagger2Validator(swaggerDocument);
// some operationId corresponding to a given swagger document route
const operationId = 'namespace.entity.action';
const validator = validators[operationId];
if (!validator) {
// there is no validator matching the given operationId
}
// Note: 'pathParameters' might not be provided if 'path' is
// provided and vice versa
const requestValidationErrors = await validator.request({
query,
body,
files,
headers,
pathParameters,
path
});
if (requestValidationErrors.length > 0) {
// there are request validation errors
}
const responseValidationErrors = await validator.response({status, body});
if (responseValidationErrors.length > 0) {
// there are response validation errors
}
Swagger 2 request-response validator
License
softwaregroup-bg/ut-swagger2-validator
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Swagger 2 request-response validator
Resources
License
Stars
Watchers
Forks
Packages 0
No packages published