• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

johnhof/swagger-injector: Delivering swagger docs through Node middleware

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

johnhof/swagger-injector

开源软件地址:

https://github.com/johnhof/swagger-injector

开源编程语言:

JavaScript 100.0%

开源软件介绍:

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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap