Installations
npm install express-jsdoc-swagger
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>= 10.0.0
Node Version
14.20.0
NPM Version
6.14.17
Score
56.8
Supply Chain
96
Quality
76.8
Maintenance
100
Vulnerability
97.9
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
Download Statistics
Total Downloads
1,894,870
Last Day
1,165
Last Week
13,199
Last Month
69,845
Last Year
685,668
GitHub Statistics
219 Stars
249 Commits
31 Forks
4 Watching
14 Branches
20 Contributors
Bundle Size
2.16 MB
Minified
707.16 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.8.0
Package Id
express-jsdoc-swagger@1.8.0
Unpacked Size
72.48 kB
Size
21.64 kB
File Count
53
NPM Version
6.14.17
Node Version
14.20.0
Total Downloads
Cumulative downloads
Total Downloads
1,894,870
Last day
-69.4%
1,165
Compared to previous day
Last week
-22.6%
13,199
Compared to previous week
Last month
21.9%
69,845
Compared to previous month
Last year
14.6%
685,668
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
express-jsdoc-swagger
With this library, you can document your express endpoints using swagger OpenAPI 3 Specification without writing YAML or JSON. You can write comments similar to jsdoc
on each endpoint, and the dependecy is going to create the swagger UI.
Table of Contents
Prerequisites
This library assumes you are using:
Installation
npm i express-jsdoc-swagger
Basic Usage
1// index.js file 2const express = require('express'); 3const expressJSDocSwagger = require('express-jsdoc-swagger'); 4 5const options = { 6 info: { 7 version: '1.0.0', 8 title: 'Albums store', 9 license: { 10 name: 'MIT', 11 }, 12 }, 13 security: { 14 BasicAuth: { 15 type: 'http', 16 scheme: 'basic', 17 }, 18 }, 19 // Base directory which we use to locate your JSDOC files 20 baseDir: __dirname, 21 // Glob pattern to find your jsdoc files (multiple patterns can be added in an array) 22 filesPattern: './**/*.js', 23 // URL where SwaggerUI will be rendered 24 swaggerUIPath: '/api-docs', 25 // Expose OpenAPI UI 26 exposeSwaggerUI: true, 27 // Expose Open API JSON Docs documentation in `apiDocsPath` path. 28 exposeApiDocs: false, 29 // Open API JSON Docs endpoint. 30 apiDocsPath: '/v3/api-docs', 31 // Set non-required fields as nullable by default 32 notRequiredAsNullable: false, 33 // You can customize your UI options. 34 // you can extend swagger-ui-express config. You can checkout an example of this 35 // in the `example/configuration/swaggerOptions.js` 36 swaggerUiOptions: {}, 37 // multiple option in case you want more that one instance 38 multiple: true, 39}; 40 41const app = express(); 42const PORT = 3000; 43 44expressJSDocSwagger(app)(options); 45 46/** 47 * GET /api/v1 48 * @summary This is the summary of the endpoint 49 * @return {object} 200 - success response 50 */ 51app.get('/api/v1', (req, res) => res.json({ 52 success: true, 53})); 54 55app.listen(PORT, () => console.log(`Example app listening at http://localhost:${PORT}`));
Basic Examples
- Basic configuration options.
1const options = { 2 info: { 3 version: '1.0.0', 4 title: 'Albums store', 5 license: { 6 name: 'MIT', 7 }, 8 }, 9 security: { 10 BasicAuth: { 11 type: 'http', 12 scheme: 'basic', 13 }, 14 }, 15 baseDir: __dirname, 16 // Glob pattern to find your jsdoc files (multiple patterns can be added in an array) 17 filesPattern: './**/*.js', 18};
- Components definition
1/** 2 * A song type 3 * @typedef {object} Song 4 * @property {string} title.required - The title 5 * @property {string} artist - The artist 6 * @property {number} year - The year - double 7 */
- Endpoint which returns a
Songs
model array in the response.
1/** 2 * GET /api/v1/albums 3 * @summary This is the summary of the endpoint 4 * @tags album 5 * @return {array<Song>} 200 - success response - application/json 6 */ 7app.get('/api/v1/albums', (req, res) => ( 8 res.json([{ 9 title: 'abum 1', 10 }]) 11));
- Endpoint PUT with body and path params which returns a
Songs
model array in the response.
1/** 2 * PUT /api/v1/albums/{id} 3 * @summary Update album 4 * @tags album 5 * @param {string} name.path - name param description 6 * @param {Song} request.body.required - songs info 7 * @return {array<Song>} 200 - success response - application/json 8 */ 9app.put('/api/v1/albums/:id', (req, res) => ( 10 res.json([{ 11 title: 'abum 1', 12 }]) 13));
- Basic endpoint definition with tags, params and basic authentication
1/** 2 * GET /api/v1/album 3 * @summary This is the summary of the endpoint 4 * @security BasicAuth 5 * @tags album 6 * @param {string} name.query.required - name param description 7 * @return {object} 200 - success response - application/json 8 * @return {object} 400 - Bad request response 9 */ 10app.get('/api/v1/album', (req, res) => ( 11 res.json({ 12 title: 'abum 1', 13 }) 14));
- Basic endpoint definition with code example for response body
1/** 2 * GET /api/v1/albums 3 * @summary This is the summary of the endpoint 4 * @tags album 5 * @return {array<Song>} 200 - success response - application/json 6 * @example response - 200 - success response example 7 * [ 8 * { 9 * "title": "Bury the light", 10 * "artist": "Casey Edwards ft. Victor Borba", 11 * "year": 2020 12 * } 13 * ] 14 */ 15app.get('/api/v1/albums', (req, res) => ( 16 res.json([{ 17 title: 'track 1', 18 }]) 19));
You can find more examples here, or visit our documentation.
Validator
We developed a new package works as a validator of your API endpoints and the documentation you create with this package. This package is express-oas-validator.
Example
Install using the node package registry:
npm install --save express-oas-validator
We have to wait until we have the full swagger schema to initiate the validator.
1// validator.js 2const { init } = require('express-oas-validator'); 3 4const validators = instance => new Promise((resolve, reject) => { 5 instance.on('finish', (swaggerDef) => { 6 const { validateRequest, validateResponse } = init(swaggerDef); 7 resolve({ validateRequest, validateResponse }); 8 }); 9 10 instance.on('error', (error) => { 11 reject(error); 12 }); 13}); 14 15module.exports = validators; 16
You can check out this also in our example folder.
1// index.js 2const express = require('express'); 3const expressJSDocSwagger = require('express-jsdoc-swagger'); 4const validator = require('./validator'); 5 6const options = { 7 info: { 8 version: '1.0.0', 9 title: 'Albums store', 10 license: { 11 name: 'MIT', 12 }, 13 }, 14 filesPattern: './**.js', 15 baseDir: __dirname, 16}; 17 18const app = express(); 19const instance = expressJSDocSwagger(app)(options); 20 21const serverApp = async () => { 22 const { validateRequest, validateResponse } = await validator(instance); 23 app.use(express.urlencoded({ extended: true })); 24 app.use(express.json()); 25 /** 26 * A song 27 * @typedef {object} Song 28 * @property {string} title.required - The title 29 * @property {string} artist - The artist 30 * @property {integer} year - The year 31 */ 32 33 /** 34 * POST /api/v1/songs 35 * @param {Song} request.body.required - song info 36 * @return {object} 200 - song response 37 */ 38 app.post('/api/v1/songs', validateRequest(), (req, res) => res.send('You save a song!')); 39 40 /** 41 * POST /api/v1/name 42 * @param {string} request.body.required - name body description 43 * @return {object} 200 - song response 44 */ 45 app.post('/api/v1/name', (req, res, next) => { 46 try { 47 // Validate response 48 validateResponse('Error string', req); 49 return res.send('Hello World!'); 50 } catch (error) { 51 return next(error); 52 } 53 }); 54 55 /** 56 * GET /api/v1/authors 57 * @summary This is the summary or description of the endpoint 58 * @param {string} name.query.required - name param description - enum:type1,type2 59 * @param {array<string>} license.query - name param description 60 * @return {object} 200 - success response - application/json 61 */ 62 app.get('/api/v1/authors', validateRequest({ headers: false }), (req, res) => ( 63 res.json([{ 64 title: 'album 1', 65 }]) 66 )); 67 68 // eslint-disable-next-line no-unused-vars 69 app.use((err, req, res, next) => { 70 res.status(err.status).json(err); 71 }); 72 73 return app; 74}; 75 76const PORT = process.env.PORT || 4000; 77 78serverApp() 79 .then(app => 80 app.listen(PORT, () => 81 console.log(`Listening PORT: ${PORT}`) 82 )) 83 .catch((err) => { 84 console.error(err); 85 process.exit(1); 86 });
You can visit our documentation.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind welcome!
No vulnerabilities found.
Reason
9 commit(s) out of 30 and 6 issue activity out of 30 found in the last 90 days -- score normalized to 10
Reason
no vulnerabilities detected
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: : LICENSE.md:1
Reason
no binaries found in the repo
Reason
update tool detected
Details
- Info: Dependabot detected
Reason
branch protection is not maximal on development and all release branches
Details
- Info: 'force pushes' disabled on branch 'master'
- Info: 'allow deletion' disabled on branch 'master'
- Info: status check found to merge onto on branch 'master'
- Warn: number of required reviewers is only 1 on branch 'master'
Reason
GitHub code reviews found for 22 commits out of the last 30 -- score normalized to 7
Details
- Warn: no reviews found for commit: 0a5af4644fc921425dbd1d46a34a9ca1ade7a134
- Warn: no reviews found for commit: 8f7140fd4482ad148e58c4e22899ea523c15ba9f
- Warn: no reviews found for commit: 57abbfb86475dd145d235bcfdb35558fd6446870
- Warn: no reviews found for commit: cead052b331164042cc03fc4d07525e57eecff37
- Warn: no reviews found for commit: 972b122594523352f9f1a628043c0f98847b92f6
- Warn: no reviews found for commit: ef64790e885f0fdb6cd56e2a6b97077bd13a341b
- Warn: no reviews found for commit: 2fe1cb8b1dac74bf90c556cc5a2989adf8b715bb
- Warn: no reviews found for commit: 580a07c469ba823cd7c60ef53e4ce54eb26eaecc
Reason
dependency not pinned by hash detected -- score normalized to 7
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/billionbd/TorrentShare/npm-publish.yml/0.9?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/billionbd/TorrentShare/npm-publish.yml/0.9?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/runTests.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/billionbd/TorrentShare/runTests.yml/0.9?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/runTests.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/billionbd/TorrentShare/runTests.yml/0.9?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/runTests.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/billionbd/TorrentShare/runTests.yml/0.9?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/runTests.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/billionbd/TorrentShare/runTests.yml/0.9?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/runTests.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/billionbd/TorrentShare/runTests.yml/0.9?enable=pin
- Info: Dockerfile dependencies are pinned
- Info: no insecure (not pinned by hash) dependency downloads found in Dockerfiles
- Info: no insecure (not pinned by hash) dependency downloads found in shell scripts
Reason
no badge detected
Reason
non read-only tokens detected in GitHub workflows
Details
- Warn: no topLevel permission defined: .github/workflows/npm-publish.yml:1: update your workflow using https://app.stepsecurity.io/secureworkflow/billionbd/TorrentShare/npm-publish.yml/0.9?enable=permissions
- Warn: no topLevel permission defined: .github/workflows/runTests.yml:1: update your workflow using https://app.stepsecurity.io/secureworkflow/billionbd/TorrentShare/runTests.yml/0.9?enable=permissions
Reason
security policy file not detected
Reason
project is not fuzzed
Score
6.9
/10
Last Scanned on 2022-08-15
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 MoreOther packages similar to express-jsdoc-swagger
swagger-jsdoc-express
Parses JSDoc comments from files and strings and set ups Swagger UI from it, to be used with Express framework.
express-jsdoc-swagger-extended
Swagger OpenAPI 3.x generator
swagger-express-jsdoc
Generates swagger JSDoc with express
@aquilacms/express-jsdoc-swagger
Swagger OpenAPI 3.x generator