forked from ErickWendel/palestra-impacta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexemplo5-swagger.js
101 lines (97 loc) · 2.56 KB
/
exemplo5-swagger.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const Hapi = require('hapi');
const Joi = require('joi');
const Inert = require('inert');
const Vision = require('vision');
const HapiSwagger = require('hapi-swagger');
const server = new Hapi.Server();
server.connection({ port: 3000 });
server.register([
Inert,
Vision,
{
'register': HapiSwagger,
'options': { info: { 'title': 'Minha API', 'version': "1.0" } },
}
], (err) => {
server.start(() => {
console.log('server rodando!');
});
});
server.route([
{
method: 'GET',
path: '/products',
config: {
handler: (req, reply) => {
return reply([]);
},
description: 'Listar todos os produtos',
notes: 'Retorna os produtos',
tags: ['api'],
validate: {
query: {
nome: Joi.string()
.required()
// .description('nome do produto')
}
}
}
},
{
method: 'POST',
path: '/products',
config: {
handler: (req, reply) => {
return reply([]);
},
description: 'Listar todos os produtos',
notes: 'Retorna os produtos',
tags: ['api'],
validate: {
query: {
nome: Joi.string()
.required()
// .description('nome do produto')
}
}
}
},
{
method: 'PUT',
path: '/products/:id',
config: {
handler: (req, reply) => {
return reply([]);
},
description: 'Listar todos os produtos',
notes: 'Retorna os produtos',
tags: ['api'],
validate: {
query: {
nome: Joi.string()
.required()
// .description('nome do produto')
}
}
}
},
{
method: 'DELETE',
path: '/products',
config: {
handler: (req, reply) => {
return reply([]);
},
description: 'Listar todos os produtos',
notes: 'Retorna os produtos',
tags: ['api'],
validate: {
query: {
nome: Joi.string()
.required()
// .description('nome do produto')
}
}
}
}
]);