Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including oas-normalize with all npm packages installed. Try it out:

var oasNormalize = require("oas-normalize")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

oas-normalize v0.0.3

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

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!


npm install oas-normalize --save


It's pretty simple:

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

const oas = new OAS(''); // Or a string, pathname, JSON blob, whatever
oas.validate((err, spec) => {
  if (err) {
  console.log(spec); // spec will always be JSON, and valid


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:

FunctionWhat 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.


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free