mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-12 12:21:34 +00:00
Initial OpenApiValidator middleware
This commit is contained in:
parent
89685b677b
commit
327ddd8ec5
1 changed files with 18 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
const Path = require('path')
|
||||
const Sequelize = require('sequelize')
|
||||
const express = require('express')
|
||||
const OpenApiValidator = require('express-openapi-validator')
|
||||
const http = require('http')
|
||||
const util = require('util')
|
||||
const fs = require('./libs/fsExtra')
|
||||
|
|
@ -203,6 +204,23 @@ class Server {
|
|||
next()
|
||||
})
|
||||
|
||||
// Install the OpenApiValidator middleware
|
||||
const apiSpec = Path.join(__dirname, 'openapi.json')
|
||||
app.use(
|
||||
OpenApiValidator.middleware({
|
||||
apiSpec: apiSpec,
|
||||
validateRequests: true,
|
||||
validateResponses: {
|
||||
onError: (error, body, req) => {
|
||||
console.log(`Response body fails validation: `, error)
|
||||
console.log(`Emitted from:`, req.originalUrl)
|
||||
console.debug(body)
|
||||
}
|
||||
},
|
||||
ignoreUndocumented: true
|
||||
})
|
||||
)
|
||||
|
||||
// parse cookies in requests
|
||||
app.use(cookieParser())
|
||||
// enable express-session
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue