node-swagger-middleware
v2.4.1
Published
[![codecov](https://codecov.io/gh/davidNHK/node-swagger-middleware/branch/development/graph/badge.svg)](https://codecov.io/gh/davidNHK/node-swagger-middleware) [![Build Status](https://travis-ci.org/davidNHK/node-swagger-middleware.svg?branch=development)
Downloads
29
Readme
node-swagger-middleware
Project on top of sway and swagger-combine to provide middleware for express request/response validate
Installation
yarn add node-swagger-middleware
Example Usage
Express Example App
const express = require("express")
const swaggerCombine = require("swagger-combine")
const {
createExpressMiddleware,
ValidationError
} = require("node-swagger-middleware")
createExpressApp = async () => {
const app = express()
const swaggerFile = await swaggerCombine(`${__dirname}/swagger/index.yml`)
app.use(express.json())
app.use(await createExpressMiddleware(swaggerFile))
app.use((err, req, res, next) => {
if (err instanceof ValidationError) {
res.status(400)
} else {
res.status(500)
}
res.send({
err
})
})
return app
}
TODO
Support default value, type casing on request parameters