Skip to content

Instantly share code, notes, and snippets.

@DavidBiesack
Last active November 7, 2017 18:15
Show Gist options
  • Save DavidBiesack/51aff07f3b576eaca4d6e94d24efc1b6 to your computer and use it in GitHub Desktop.
Save DavidBiesack/51aff07f3b576eaca4d6e94d24efc1b6 to your computer and use it in GitHub Desktop.
Command line shell script for running sway on an OpenAPI document from a console
#!/usr/bin/env node
// Validate an OpenAPI document using sway library, https://www.npmjs.com/package/sway
//
// Install node (npm) and then install sway to use this:
//
// npm install sway --save # (This is only needed once, to install sway)
//
// From original source by Taylor Singletary (@episod), as shared on APIEvangelists slack #openapi Oct 31 2017
//
// Usage if saved as `sway` in your PATH:
//
// sway open-api.json
// sway open-api.yaml
// sway http://petstore.swagger.io/v2/swagger.json
//
// To do: extend sway with our own Apiture rules
const util = require('util')
const sway = require("sway");
const openApi = process.argv[2]; // [0] is node; [1] is this .js file, [2] is the Open API document on the command line
sway.create({definition: openApi})
.then(function (api) {
console.log('Documentation URL: ', api.documentationUrl);
const results = api.validate();
console.log(util.inspect(results, false, null));
}, function (err) {
console.error(err.stack);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment