Skip to content

Commit 04a3d16

Browse files
authored
Fixes all examples for v4.0.0 (#621)
1 parent 4d69fe1 commit 04a3d16

File tree

5 files changed

+186
-236
lines changed

5 files changed

+186
-236
lines changed

examples/dynamic-openapi-joi.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

examples/dynamic-openapi.js

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -26,91 +26,92 @@ fastify.register(require('../index'), {
2626
exposeRoute: true
2727
})
2828

29-
fastify.put('/some-route/:id', {
30-
schema: {
31-
description: 'post some data',
32-
tags: ['user', 'code'],
33-
summary: 'qwerty',
34-
security: [{ apiKey: [] }],
35-
params: {
36-
type: 'object',
37-
properties: {
38-
id: {
39-
type: 'string',
40-
description: 'user id'
29+
fastify.register(async function (fastify) {
30+
fastify.put('/some-route/:id', {
31+
schema: {
32+
description: 'post some data',
33+
tags: ['user', 'code'],
34+
summary: 'qwerty',
35+
security: [{ apiKey: [] }],
36+
params: {
37+
type: 'object',
38+
properties: {
39+
id: {
40+
type: 'string',
41+
description: 'user id'
42+
}
4143
}
42-
}
43-
},
44-
body: {
45-
type: 'object',
46-
properties: {
47-
hello: { type: 'string' },
48-
obj: {
44+
},
45+
body: {
46+
type: 'object',
47+
properties: {
48+
hello: { type: 'string' },
49+
obj: {
50+
type: 'object',
51+
properties: {
52+
some: { type: 'string' }
53+
}
54+
}
55+
}
56+
},
57+
response: {
58+
201: {
59+
description: 'Succesful response',
60+
type: 'object',
61+
properties: {
62+
hello: { type: 'string' }
63+
}
64+
},
65+
default: {
66+
description: 'Default response',
4967
type: 'object',
5068
properties: {
51-
some: { type: 'string' }
69+
foo: { type: 'string' }
5270
}
5371
}
5472
}
55-
},
56-
response: {
57-
201: {
58-
description: 'Succesful response',
73+
}
74+
}, (req, reply) => { reply.send({ hello: `Hello ${req.body.hello}` }) })
75+
76+
fastify.post('/some-route/:id', {
77+
schema: {
78+
description: 'post some data',
79+
summary: 'qwerty',
80+
security: [{ apiKey: [] }],
81+
params: {
5982
type: 'object',
6083
properties: {
61-
hello: { type: 'string' }
84+
id: {
85+
type: 'string',
86+
description: 'user id'
87+
}
6288
}
6389
},
64-
default: {
65-
description: 'Default response',
90+
body: {
6691
type: 'object',
6792
properties: {
68-
foo: { type: 'string' }
69-
}
70-
}
71-
}
72-
}
73-
}, (req, reply) => { reply.send({ hello: `Hello ${req.body.hello}` }) })
74-
75-
fastify.post('/some-route/:id', {
76-
schema: {
77-
description: 'post some data',
78-
summary: 'qwerty',
79-
security: [{ apiKey: [] }],
80-
params: {
81-
type: 'object',
82-
properties: {
83-
id: {
84-
type: 'string',
85-
description: 'user id'
93+
hello: { type: 'string' },
94+
obj: {
95+
type: 'object',
96+
properties: {
97+
some: { type: 'string' }
98+
}
99+
}
86100
}
87-
}
88-
},
89-
body: {
90-
type: 'object',
91-
properties: {
92-
hello: { type: 'string' },
93-
obj: {
101+
},
102+
response: {
103+
201: {
104+
description: 'Succesful response',
94105
type: 'object',
95106
properties: {
96-
some: { type: 'string' }
107+
hello: { type: 'string' }
97108
}
98109
}
99110
}
100-
},
101-
response: {
102-
201: {
103-
description: 'Succesful response',
104-
type: 'object',
105-
properties: {
106-
hello: { type: 'string' }
107-
}
108-
}
109111
}
110-
}
111-
}, (req, reply) => { reply.send({ hello: `Hello ${req.body.hello}` }) })
112+
}, (req, reply) => { reply.send({ hello: `Hello ${req.body.hello}` }) })
113+
})
112114

113-
fastify.listen(3000, err => {
115+
fastify.listen({ port: 3000 }, err => {
114116
if (err) throw err
115-
console.log('listening')
116117
})

examples/dynamic-overwrite-endpoint.js

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,46 @@ fastify.register(require('../index'), {
1818
routePrefix: '/swagger-docs'
1919
})
2020

21-
fastify.put('/some-route/:id', {
22-
schema: {
23-
description: 'post some data',
24-
tags: ['user', 'code'],
25-
summary: 'qwerty',
26-
params: {
27-
type: 'object',
28-
properties: {
29-
id: {
30-
type: 'string',
31-
description: 'user id'
32-
}
33-
}
34-
},
35-
body: {
36-
type: 'object',
37-
properties: {
38-
hello: { type: 'string' },
39-
obj: {
40-
type: 'object',
41-
properties: {
42-
some: { type: 'string' }
21+
fastify.register(async function (fastify) {
22+
fastify.put('/some-route/:id', {
23+
schema: {
24+
description: 'post some data',
25+
tags: ['user', 'code'],
26+
summary: 'qwerty',
27+
params: {
28+
type: 'object',
29+
properties: {
30+
id: {
31+
type: 'string',
32+
description: 'user id'
4333
}
4434
}
45-
}
46-
},
47-
response: {
48-
201: {
49-
description: 'Succesful response',
35+
},
36+
body: {
5037
type: 'object',
5138
properties: {
52-
hello: { type: 'string' }
39+
hello: { type: 'string' },
40+
obj: {
41+
type: 'object',
42+
properties: {
43+
some: { type: 'string' }
44+
}
45+
}
46+
}
47+
},
48+
response: {
49+
201: {
50+
description: 'Succesful response',
51+
type: 'object',
52+
properties: {
53+
hello: { type: 'string' }
54+
}
5355
}
5456
}
5557
}
56-
}
57-
}, (req, reply) => {})
58+
}, (req, reply) => {})
59+
})
5860

59-
fastify.listen(3000, err => {
61+
fastify.listen({ port: 3000 }, err => {
6062
if (err) throw err
61-
console.log('listening')
6263
})

0 commit comments

Comments
 (0)