forked from fastify/fastify-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (29 loc) · 880 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
32
33
34
'use strict'
const fp = require('fastify-plugin')
const { formatParamUrl } = require('./lib/util/format-param-url')
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']"))
}
}
}
module.exports = fp(fastifySwagger, {
fastify: '5.x',
name: '@fastify/swagger'
})
module.exports.fastifySwagger = fastifySwagger
module.exports.default = fastifySwagger
module.exports.formatParamUrl = formatParamUrl