UNPKG

626 BJavaScriptView Raw
1'use strict'
2
3const fastify = require('../fastify')()
4
5fastify.addSchema({
6 $id: 'https://foo/common.json',
7 definitions: {
8 response: {
9 $id: '#reply',
10 type: 'object',
11 properties: {
12 hello: {
13 $id: '#bar',
14 type: 'string'
15 }
16 }
17 }
18 }
19})
20
21const opts = {
22 schema: {
23 response: {
24 200: { $ref: 'https://foo/common.json#reply' }
25 }
26 }
27}
28
29fastify
30 .get('/', opts, function (req, reply) {
31 reply.send({ hello: 'world' })
32 })
33
34fastify.listen(3000, err => {
35 if (err) throw err
36 console.log(`server listening on ${fastify.server.address().port}`)
37})