Installations
npm install koa2-swagger-ui
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
22.11.0
NPM Version
10.9.0
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (57.07%)
Handlebars (42.93%)
Developer
scttcper
Download Statistics
Total Downloads
5,701,110
Last Day
8,364
Last Week
33,394
Last Month
150,613
Last Year
1,887,558
GitHub Statistics
106 Stars
359 Commits
32 Forks
5 Watching
3 Branches
2 Contributors
Bundle Size
238.81 kB
Minified
77.60 kB
Minified + Gzipped
Package Meta Information
Latest Version
5.11.0
Package Id
koa2-swagger-ui@5.11.0
Unpacked Size
20.96 kB
Size
7.79 kB
File Count
8
NPM Version
10.9.0
Node Version
22.11.0
Publised On
18 Nov 2024
Total Downloads
Cumulative downloads
Total Downloads
5,701,110
Last day
10.2%
8,364
Compared to previous day
Last week
-14.7%
33,394
Compared to previous week
Last month
1%
150,613
Compared to previous month
Last year
31%
1,887,558
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
koa2-swagger-ui
Host swagger ui at a given directory from your koa v2 app
Inspired by:
- swagger-injector for serving on a specific route
- hapi-swaggered-ui for serving files from node_modules using a handlebars driven index.html
install
npm install koa2-swagger-ui --save
config
for more swaggerOptions see swagger-ui defaults:
1title: 'swagger', // page title 2oauthOptions: {}, // passed to initOAuth 3swaggerOptions: { // passed to SwaggerUi() 4 dom_id: 'swagger-ui-container', 5 url: 'http://petstore.swagger.io/v2/swagger.json', // link to swagger.json 6 supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'], 7 docExpansion: 'none', 8 jsonEditor: false, 9 defaultModelRendering: 'schema', 10 showRequestHeaders: false, 11 swaggerVersion: 'x.x.x' // read from package.json, 12 validatorUrl: null, // disable swagger-ui validator 13}, 14routePrefix: '/docs', // route where the view is returned 15specPrefix: '/docs/spec', // route where the spec is returned 16exposeSpec: false, // expose spec file 17hideTopbar: false, // hide swagger top bar 18favicon: '/favicon.png', // default favicon 19customCSS: `h1 { color: red }`, // Add Custom CSS on the html
example
1import Koa from 'koa'; 2import { koaSwagger } from 'koa2-swagger-ui'; 3 4const app = new Koa(); 5 6app.use( 7 koaSwagger({ 8 routePrefix: '/swagger', // host at /swagger instead of default /docs 9 swaggerOptions: { 10 url: 'http://petstore.swagger.io/v2/swagger.json', // example path to json 11 }, 12 }), 13); 14 15app.listen(3000);
example with koa-router and yaml source
depends on yamljs to turn your Yaml into a JS object
npm install --save yamljs
1const Koa = require('koa'); 2const Router = require('koa-router'); 3const yamljs = require('yamljs'); 4const koaSwagger = require('koa2-swagger-ui'); 5 6const router = new Router({ prefix: '/' }); 7 8const app = new Koa(); 9const router = new Router(); 10 11// .load loads file from root. 12const spec = yamljs.load('./openapi.yaml'); 13 14// example 1 using router.use() 15router.use(koaSwagger({ swaggerOptions: { spec } })); 16 17// example 2 using more explicit .get() 18router.get('/docs', koaSwagger({ routePrefix: false, swaggerOptions: { spec } })); 19 20app.use(router.routes()); 21app.listen(3000);
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
packaging workflow detected
Details
- Info: Project packages its releases by way of GitHub Actions.: .github/workflows/ci.yml:29
Reason
2 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6
Reason
Found 8/30 approved changesets -- score normalized to 2
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/scttcper/koa2-swagger-ui/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/scttcper/koa2-swagger-ui/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/scttcper/koa2-swagger-ui/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/scttcper/koa2-swagger-ui/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/scttcper/koa2-swagger-ui/ci.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 3 third-party GitHubAction dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 19 are checked with a SAST tool
Score
3.8
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More