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

Darmikon/swagger-ui-koa: Swagger UI module for koa 2

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

开源软件名称:

Darmikon/swagger-ui-koa

开源软件地址:

https://github.com/Darmikon/swagger-ui-koa

开源编程语言:

HTML 75.5%

开源软件介绍:

Swagger UI Koa 2

Forked from swagger-ui-express

Adds middleware to your koa app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.

Updated to Swagger 3.0.17

Usage

In app's package.json

"swagger-ui-koa": "latest" // or desired version

Setup swagger-app-wrapper.js

import swaggerUi from 'swagger-ui-koa';
import swaggerJSDoc from 'swagger-jsdoc';
import convert from 'koa-convert';
import mount from 'koa-mount';
//import swaggerDocument from './swagger.json'; //also can be used

export default function (app) {
  //without jsdoc from swagger.json
  //app.use(swaggerUi.serve); //serve swagger static files
  //app.use(convert(mount('/swagger', swaggerUi.setup(swaggerDocument)))); //mount endpoint for access

  //with jsdoc
  const options = {
    swaggerDefinition: {
      info: {
        title: 'API', // Title (required)
        version: '2.0.0', // Version (required)
      },
    },
    apis: [
      './src/module/swagger/swagger.yaml',
      './src/routes/*.js', // Path to the API docs from root
      './src/module/swagger/parameters.yaml'
    ],
  };
  // Initialize swagger-jsdoc -> returns validated swagger spec in json format
  const swaggerSpec = swaggerJSDoc(options);
  app.use(swaggerUi.serve); //serve swagger static files
  app.use(convert(mount('/swagger', swaggerUi.setup(swaggerSpec)))); //mount endpoint for access
}

Open http://<app_host>:<app_port>/swagger in your browser to view the documentation.

swagger-jsdoc

Swagger Explorer

By default the Swagger Explorer bar is hidden, to display it pass true as the second parameter to the setup function:

const express = require('express');
const app = express();
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');

var showExplorer = true;
  ...
  swaggerUi.setup(swaggerDocument, showExplorer)
  ...

Custom swagger options

To pass custom options e.g. validatorUrl, to the SwaggerUi client pass an object as the third parameter:

var showExplorer = true;
var options = {
	validatorUrl : null
};
...
swaggerUi.setup(swaggerDocument, showExplorer, options));
...

Custom CSS styles

To customize the style of the swagger page, you can pass custom CSS as the fourth parameter.

E.g. to hide the swagger header:

var showExplorer = false;
var options = {};
var customCss = '#header { display: none }';

...
swaggerUi.setup(swaggerDocument, showExplorer, options, customCss));
...

Requirements

  • Koa 2



鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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