express-jsdoc-swagger
Advanced tools
Comparing version 1.6.1 to 1.6.2
{ | ||
"name": "express-jsdoc-swagger", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"description": "Swagger OpenAPI 3.x generator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
108
README.md
@@ -170,2 +170,110 @@ ![npm](https://img.shields.io/npm/v/express-jsdoc-swagger) | ||
## 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](https://github.com/BRIKEV/express-oas-validator). | ||
**Example** | ||
Install using the node package registry: | ||
``` | ||
npm install --save express-oas-validator | ||
``` | ||
After this you have to initialize using the `finish` event. More info in this [sections](eventEmitter.md). | ||
```js | ||
const instance = expressJSDocSwagger(app)(options); | ||
instance.on('finish', data => { | ||
init(data); | ||
resolve(app); | ||
}); | ||
``` | ||
This is a full example of how it works. | ||
```js | ||
const express = require('express'); | ||
const expressJSDocSwagger = require('express-jsdoc-swagger'); | ||
const { init, validateRequest, validateResponse } = require('express-oas-validator'); | ||
const options = { | ||
info: { | ||
version: '1.0.0', | ||
title: 'Albums store', | ||
license: { | ||
name: 'MIT', | ||
}, | ||
}, | ||
filesPattern: './**.js', | ||
baseDir: __dirname, | ||
}; | ||
const app = express(); | ||
const instance = expressJSDocSwagger(app)(options); | ||
const serverApp = () => new Promise(resolve => { | ||
instance.on('finish', data => { | ||
init(data); | ||
resolve(app); | ||
}); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
/** | ||
* A song | ||
* @typedef {object} Song | ||
* @property {string} title.required - The title | ||
* @property {string} artist - The artist | ||
* @property {integer} year - The year | ||
*/ | ||
/** | ||
* POST /api/v1/songs | ||
* @param {Song} request.body.required - song info | ||
* @return {object} 200 - song response | ||
*/ | ||
app.post('/api/v1/songs', validateRequest(), (req, res) => res.send('You save a song!')); | ||
/** | ||
* POST /api/v1/name | ||
* @param {string} request.body.required - name body description | ||
* @return {object} 200 - song response | ||
*/ | ||
app.post('/api/v1/name', (req, res, next) => { | ||
try { | ||
// Validate response | ||
validateResponse('Error string', req); | ||
return res.send('Hello World!'); | ||
} catch (error) { | ||
return next(error); | ||
} | ||
}); | ||
/** | ||
* GET /api/v1/authors | ||
* @summary This is the summary or description of the endpoint | ||
* @param {string} name.query.required - name param description - enum:type1,type2 | ||
* @param {array<string>} license.query - name param description | ||
* @return {object} 200 - success response - application/json | ||
*/ | ||
app.get('/api/v1/authors', validateRequest({ headers: false }), (req, res) => ( | ||
res.json([{ | ||
title: 'album 1', | ||
}]) | ||
)); | ||
// eslint-disable-next-line no-unused-vars | ||
app.use((err, req, res, next) => { | ||
res.status(err.status).json(err); | ||
}); | ||
}); | ||
module.exports = serverApp; | ||
``` | ||
You can visit our [documentation](https://brikev.github.io/express-jsdoc-swagger-docs/#/validator). | ||
## Contributors ✨ | ||
@@ -172,0 +280,0 @@ |
@@ -10,2 +10,3 @@ const examplesGenerator = require('./examples'); | ||
} = require('../utils/httpMethods'); | ||
const formatSecurity = require('./security'); | ||
@@ -17,6 +18,2 @@ const formatTags = (tags = []) => tags.map(({ description }) => { | ||
const formatSecurity = (securityValues = []) => securityValues.map(({ description }) => ({ | ||
[description]: [], | ||
})); | ||
const formatSummary = summary => (summary || {}).description || ''; | ||
@@ -23,0 +20,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70587
58
1320
308