Request and response validator against OpenAPI Specification
If you are looking for framework specific middleware, you might want to look at following libraries that use oas3-chow-chow under the hood.
$ yarn add oas3-chow-chow
$ # Or
$ npm i oas3-chow-chow
import ChowChow from "oas3-chow-chow";
import * as fs from "fs";
import * as yaml from "js-yaml";
var doc = yaml.safeLoad(fs.readFileSync("./openapi.yml", "utf8"));
const chow = new ChowChow(doc);
chow.validateRequest("./books", {
method: "post",
query: {
expand: ["document", "author"]
},
body: {
name: "a nice book",
author: "me me me"
}
});
chow.validateResponse("./books", {
method: "post",
header: {
"content-type": "application/json"
},
body: {
name: "a nice book",
author: "me me me"
}
});