4.0.1 • Published 5 years ago

swagger-injector v4.0.1

Weekly downloads
265
License
MIT
Repository
github
Last release
5 years ago

Swagger Injector

Build Status

Adaptation of swagger ui to render the swagger view of a server's swagger documentation for a specified route.

If you're unfamiliar with swagger, I highly recommend checking it out.

Key

Usage

Koa

Build for ^2.x

  • Assume ./swagger.json is a valid json file
  • Working example
    • Run $ npm install && node examples/koa
    • Request localhost:3000/swagger
let Koa = require('koa');
let swagger = require('swagger-injector');

let app = new Koa();

app.use(swagger.koa({
  path: `${__dirname}/swagger.json`,
}));

app.listen(3000);

Express

  • Assume ./swagger.json is a valid json file
  • NOTE: authentication requires cookie-parser
  • Working example
    • Run $ npm install && node examples/express
    • Request localhost:3000/swagger
let express = require('express');
let cookieParser = require('cookie-parser');
let swagger = require('swagger-injector');

let app = express();

app.use(cookieParser()); // REQUIRED
app.use(swagger.express({
  path: `${__dirname}/swagger.json`
}));

app.listen(3000);

Configuration

The following configuration example is a copy of the default configuration

{
  path: './swagger.json', // Path to swagger file
  swagger: false, // swagger json. If not set, it is read from the `path` file
  prefix: '', // Prefix applied to all routes
  assets: '/_swagger_', // Prefix for all assets, appended to prefix
  route: '/swagger', // Router to serve documentation
  css: false, // Path to the css OR css string
  unauthorized: false, // Unauth handler
  dist: '/dist', // Path to dist directory
  authentication: {
    sources: ['query', 'body'], // Accepted sources of auth
    key: false, // Key for the auth
    value: false // Value for the auth
  }
}

Author

License

MIT

4.0.1

5 years ago

4.0.0

6 years ago

3.0.0

7 years ago

2.0.9

7 years ago

2.0.8

7 years ago

2.0.7

7 years ago

2.0.6

7 years ago

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.2.0

8 years ago

1.1.2

8 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago