Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johnhof/swagger-injector
Delivering swagger docs through Node middleware
https://github.com/johnhof/swagger-injector
express koa openapi openapi-specification swagger
Last synced: 2 months ago
JSON representation
Delivering swagger docs through Node middleware
- Host: GitHub
- URL: https://github.com/johnhof/swagger-injector
- Owner: johnhof
- License: mit
- Created: 2015-06-19T18:22:37.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T09:30:28.000Z (about 2 years ago)
- Last Synced: 2024-10-09T14:43:21.348Z (3 months ago)
- Topics: express, koa, openapi, openapi-specification, swagger
- Language: JavaScript
- Homepage:
- Size: 3.2 MB
- Stars: 23
- Watchers: 3
- Forks: 46
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Swagger Injector
[![Build Status](https://travis-ci.org/johnhof/swagger-injector.svg?branch=master)](https://travis-ci.org/johnhof/swagger-injector)
Adaptation of [swagger ui](https://github.com/swagger-api/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](http://swagger.io/).
# Key
- [Usage](#usage)
- [Koa](#koa)
- [Express](#express)
- [Defaults](#defaults)
- [Configuration](#configuration)# Usage
## Koa
**Build for ^2.x**
* Assume ./swagger.json is a valid json file
* [Working example](https://github.com/johnhof/swagger-injector/tree/master/examples/koa.js)
* Run `$ npm install && node examples/koa`
* Request `localhost:3000/swagger````javascript
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](https://github.com/johnhof/swagger-injector/tree/master/examples/express.js)
* Run `$ npm install && node examples/express`
* Request `localhost:3000/swagger````javascript
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
```javascript
{
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
- [John Hofrichter](https://github.com/johnhof)
# License
MIT