Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 1.16 KB

README.md

File metadata and controls

53 lines (41 loc) · 1.16 KB

oas3-chow-chow

Request and response validator against OpenAPI Specification

Build Status npm

Notes

If you are looking for framework specific middleware, you might want to look at following libraries that use oas3-chow-chow under the hood.

koa-oas3

Installation

$ yarn add oas3-chow-chow
$ # Or
$ npm i oas3-chow-chow

Usage

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"
  }
});