Git Product home page Git Product logo

open-swagger-ui's Introduction

open-swagger-ui

An easy CLI to open swagger.json or .yaml files in Swagger UI.

$ open-swagger-ui ./swagger.json --open # done !

Install

Requires Node >=10.

From npm,

npm i -g open-swagger-ui

From Github Package Registry. (Guide).

Type definitions are bundled with this package.

CLI Usage

$ open-swagger-ui ./swagger.json
# => starts the server.

$ open-swagger-ui ./swagger.json --open # or -O for short
# => starts server, opens it in browser.

$ open-swagger-ui <absolute-path-to-swagger.json> --port 8899
# => you can put absolute/relative path for swagger.json
# => if the requested port is not available, a random port is chosen.

# Oh yes! You can put urls too..
$ open-swagger-ui https://petstore.swagger.io/v2/swagger.json

--help for help

$ open-swagger-ui --help
Usage: open-swagger-ui [options] <swagger-file>

An easy CLI tool to open swagger.json or .yaml files in Swagger UI.

Options:
  -V, --version      output the version number
  -O, --open         Open stuff in browser
  -P, --port <port>  Preferred port. If not available, a random port is selected
  -h, --help         output usage information

APIs

You can use this as a module too, just in case you want.

const { startServerWithSwaggerFile } = require('open-swagger-ui');
// or
import { startServerWithSwaggerFile } from 'open-swagger-ui';

startServerWithSwaggerFile('./path/to/swagger.json', port)
  .then(({ app, port, swagFilePath, server }) => {
    console.log(`app started on port ${port}`);
    // app is the express server underneath
    // you may freely add routes to it like
    // app.use(stuff);
  })
  .catch(err => console.error('something went wrong', err));

The startServerWithSwaggerFile function returns express app, the HTTP server instance, port in which the file is open and the reference swagFilePath.

Licence

MIT © Vajahath Ahmed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.