-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelper.ts
76 lines (69 loc) · 1.41 KB
/
helper.ts
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
import { App } from '@tinyhttp/app'
import { makeFetch } from 'supertest-fetch'
import { addToDocs, generateDocs, serveDocs } from '../src/index'
export function initApp() {
const app = new App()
app.get(
'/users/:id',
addToDocs(
{
headers: {
authorization: 'string'
},
params: {
id: {
type: 'string',
optional: true
}
}
},
['users']
),
(_, res) => {
res.status(200).send('users list')
}
)
app.post(
'/users',
addToDocs(
{
headers: {
'csrf-token': 'string',
accept: {
type: 'string',
optional: true
}
},
params: {
_csrf: {
type: 'string',
optional: true
}
},
body: {
name: 'string',
email: 'string',
phone: {
type: 'number',
optional: true
},
score: {
type: 'array',
items: 'number'
}
}
},
['users']
),
(_, res) => {
res.status(200).send('users post')
}
)
app.get('/json', (_, res) => {
res.status(200).json(generateDocs(app, { title: 'sample app' }))
})
serveDocs(app, { title: 'sample app' })
const server = app.listen()
const fetch = makeFetch(server)
return { app, server, fetch }
}