Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Swagger UI module for koa 2

NotificationsYou must be signed in to change notification settings

Darmikon/swagger-ui-koa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Forked fromswagger-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'spackage.json

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

Setupswagger-app-wrapper.js

importswaggerUifrom'swagger-ui-koa';importswaggerJSDocfrom'swagger-jsdoc';importconvertfrom'koa-convert';importmountfrom'koa-mount';//import swaggerDocument from './swagger.json'; //also can be usedexportdefaultfunction(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 jsdocconstoptions={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 formatconstswaggerSpec=swaggerJSDoc(options);app.use(swaggerUi.serve);//serve swagger static filesapp.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 Explorer

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

constexpress=require('express');constapp=express();constswaggerUi=require('swagger-ui-express');constswaggerDocument=require('./swagger.json');varshowExplorer=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:

varshowExplorer=true;varoptions={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:

varshowExplorer=false;varoptions={};varcustomCss='#header { display: none }';...swaggerUi.setup(swaggerDocument,showExplorer,options,customCss));...

Requirements

  • Koa 2

About

Swagger UI module for koa 2

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp