Negligible Participation Metric
Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »

oas-normalize

0.0.1 • Public • Published

Swagger 2 or OAS 3? YAML or JSON? URL, path, string or object? Who cares! It just works.

This module uses a bunch of other great modules to do the heavy lifting, and normalizes everything!

Usage

It's pretty simple:

 
const OAS = require('oas-normalize');
 
const oas = new OAS('http://google.com'); // Or a string, pathname, JSON blob, whatever
oas.validate((err, spec) => {
  if (err) {
    console.log(err.errors);
    return;
  }
  console.log(spec); // spec will always be JSON, and valid
});

Helper functions

If you want some more functionality, you can do anything here:

Function What it does
oas.load(cb) Just load the file, valid or not, as JSON
oas.bundle(cb) Bring together all files into one JSON blob (but keep $refs)
oas.deref(cb) Resolve $refs
oas.validate(cb, [convertToLatest?])) Validate the whole thing!

Always return OAS 3

If you want .validate to always return a OAS 3 document, include a true as the second param:

oas.validate(action, true);

Keywords

none

install

npm i oas-normalize

Downloadsweekly downloads

293

version

0.0.1

license

ISC

last publish

collaborators

  • avatar
Report a vulnerability