1 | 'use strict'
|
2 |
|
3 | const fastify = require('../fastify')({ logger: true })
|
4 |
|
5 | fastify.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 |
|
21 | const opts = {
|
22 | schema: {
|
23 | response: {
|
24 | 200: { $ref: 'https://foo/common.json#reply' }
|
25 | }
|
26 | }
|
27 | }
|
28 |
|
29 | fastify
|
30 | .get('/', opts, function (req, reply) {
|
31 | reply.send({ hello: 'world' })
|
32 | })
|
33 |
|
34 | fastify.listen({ port: 3000 }, err => {
|
35 | if (err) {
|
36 | throw err
|
37 | }
|
38 | })
|