-
-
Notifications
You must be signed in to change notification settings - Fork 210
/
collection-format.js
52 lines (48 loc) · 1.23 KB
/
collection-format.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict'
const fastify = require('fastify')({
// Need to add a collectionFormat keyword to ajv in fastify instance
ajv: {
customOptions: {
keywords: ['collectionFormat']
}
}
})
fastify.register(require('../index'), {
exposeRoute: true
})
fastify.route({
method: 'GET',
url: '/',
schema: {
querystring: {
type: 'object',
required: ['fields'],
additionalProperties: false,
properties: {
fields: {
type: 'array',
items: {
type: 'string'
},
minItems: 1,
//
// Note that this is an Open API version 2 configuration option. The
// options changed in version 3. The plugin currently only supports
// version 2 of Open API.
//
// Put `collectionFormat` on the same property which you are defining
// as an array of values. (i.e. `collectionFormat` should be a sibling
// of the `type: "array"` specification.)
collectionFormat: 'multi'
}
}
}
},
handler (request, reply) {
reply.send(request.query.fields)
}
})
fastify.listen({ port: 3000 }, (err, addr) => {
if (err) throw err
console.log(`listening on ${addr}`)
})