在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:Darmikon/swagger-ui-koa开源软件地址:https://github.com/Darmikon/swagger-ui-koa开源编程语言:HTML 75.5%开源软件介绍:Swagger UI Koa 2Forked 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 UsageIn app's
Setup 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:// swagger-jsdocSwagger ExplorerBy 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 optionsTo 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 stylesTo 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
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论