mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-12 12:21:34 +00:00
Change: OpenApiValidator to only be created in dev
This commit is contained in:
parent
0122f88b46
commit
ac4bd0a558
1 changed files with 26 additions and 24 deletions
|
|
@ -205,30 +205,32 @@ class Server {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Install the OpenApiValidator middleware
|
// Install the OpenApiValidator middleware
|
||||||
const apiSpec = Path.join(__dirname, 'openapi.json')
|
if (Logger.isDev) {
|
||||||
app.use(
|
const apiSpec = Path.join(__dirname, 'openapi.json')
|
||||||
OpenApiValidator.middleware({
|
app.use(
|
||||||
apiSpec: apiSpec,
|
OpenApiValidator.middleware({
|
||||||
validateRequests: true,
|
apiSpec: apiSpec,
|
||||||
validateResponses: {
|
validateRequests: true,
|
||||||
onError: (error, body, req) => {
|
validateResponses: {
|
||||||
console.log(`Response body fails validation: `, error)
|
onError: (error, body, req) => {
|
||||||
console.log(`Emitted from:`, req.originalUrl)
|
console.log(`Response body fails validation: `, error)
|
||||||
console.debug(body)
|
console.log(`Emitted from:`, req.originalUrl)
|
||||||
}
|
console.debug(body)
|
||||||
},
|
}
|
||||||
formats: [
|
},
|
||||||
// Define custom format types for OpenAPI spec
|
formats: [
|
||||||
{
|
// Define custom format types for OpenAPI spec
|
||||||
name: 'uuid',
|
{
|
||||||
type: 'string',
|
name: 'uuid',
|
||||||
validate: (v) => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(v.toString())
|
type: 'string',
|
||||||
}
|
validate: (v) => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(v.toString())
|
||||||
],
|
}
|
||||||
unknownFormats: ['li_[a-z0-9]{18}', '[0-9]*'],
|
],
|
||||||
ignoreUndocumented: true
|
unknownFormats: ['li_[a-z0-9]{18}', '[0-9]*'],
|
||||||
})
|
ignoreUndocumented: true
|
||||||
)
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// parse cookies in requests
|
// parse cookies in requests
|
||||||
app.use(cookieParser())
|
app.use(cookieParser())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue