forked from fastify/fastify-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (26 loc) · 744 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict'
const fp = require('fastify-plugin')
function fastifySwagger (fastify, opts, next) {
// by default the mode is dynamic, as plugin initially was developed
opts.mode = opts.mode || 'dynamic'
switch (opts.mode) {
case 'static': {
const setup = require('./lib/mode/static')
setup(fastify, opts, next)
break
}
case 'dynamic': {
const setup = require('./lib/mode/dynamic')
setup(fastify, opts, next)
break
}
default: {
return next(new Error("unsupported mode, should be one of ['static', 'dynamic']"))
}
}
fastify.decorate('swaggerCSP', require('./static/csp.json'))
}
module.exports = fp(fastifySwagger, {
fastify: '>=3.x',
name: 'fastify-swagger'
})