-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
61 lines (55 loc) · 1.31 KB
/
utils.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
const ErrorPrefix = 'FastifyEnforceSchema'
exports.ErrorPrefix = ErrorPrefix
const SCHEMA_TYPES = {
response: 'response',
body: 'body',
params: 'params'
}
exports.SCHEMA_TYPES = SCHEMA_TYPES
exports.getErrorMessage = (data, routeOptions) => {
const { path, method } = routeOptions
if (data?.schema) {
return `${ErrorPrefix}: ${method}: ${path} is missing a schema`
}
if (data?.schemaType) {
return `${ErrorPrefix}: ${method}: ${path} is missing a ${data.schemaType} schema`
}
return `${ErrorPrefix}: In ${method}: ${path}, ${data?.message}.`
}
exports.hasProperties = (routeOptions, key, subKey = null) => {
if (!subKey) {
return !!Object.keys(routeOptions?.schema?.[key] || []).length
}
return !!Object.keys(routeOptions?.schema?.[key]?.[subKey] || []).length
}
exports.isSchemaTypeExcluded = (excludedEntity, schemaType) => {
return excludedEntity?.excludedSchemas?.includes(schemaType) || false
}
exports.isSchemaDisabled = (disabled) => {
return Object.values(SCHEMA_TYPES).every((schemaType) =>
disabled.includes(schemaType)
)
}
exports.initialExcludes = [
{
url: '/docs'
},
{
url: '/docs/uiConfig'
},
{
url: '/docs/initOAuth'
},
{
url: '/docs/json'
},
{
url: '/docs/yaml'
},
{
url: '/docs/*'
},
{
url: '/docs/static/*'
}
]