- Notifications
You must be signed in to change notification settings - Fork5
Darmikon/swagger-ui-koa
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
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
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.
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)...
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));...
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));...
- Koa 2
About
Swagger UI module for koa 2
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.