oas-normalize
Swagger 2 or OAS 3? YAML or JSON? URL, path, string or object? Who cares! It just works.
Last updated 10 days ago by jonursenbach .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install oas-normalize 
SYNC missed versions from official npm registry.

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!

Install

npm install oas-normalize --save

Usage

It's pretty simple:

const OAS = require('oas-normalize');

const oas = new OAS('https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml'); // 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
});

Errors

For validation errors, when available, you'll get back an object:

{
  "errors": [
    {
      "message": "User-friendly message",
      "path": [...array of the path to the error...]
    }
  ],
  "full": ...raw errors...
}

message is almost always there, but path is less dependable.

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!

Other little features

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

Enable local paths

For security reasons, you need to enable it. Use new OAS('./whatever.json', { enablePaths: true }) to load local files.

Current Tags

  • 2.3.0                                ...           latest (10 days ago)

16 Versions

  • 2.3.0                                ...           10 days ago
  • 2.2.2                                ...           24 days ago
  • 2.2.1                                ...           2 months ago
  • 2.2.0                                ...           3 months ago
  • 2.1.0                                ...           4 months ago
  • 2.0.2                                ...           5 months ago
  • 2.0.1                                ...           5 months ago
  • 2.0.0                                ...           6 months ago
  • 1.0.0                                ...           7 months ago
  • 0.1.1                                ...           7 months ago
  • 0.1.0                                ...           9 months ago
  • 0.0.6                                ...           10 months ago
  • 0.0.5                                ...           10 months ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Downloads
Today 1
This Week 1
This Month 38
Last Day 0
Last Week 37
Last Month 40
Dependencies (6)
Dev Dependencies (5)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |