-
Notifications
You must be signed in to change notification settings - Fork 8
/
mandatoryTest_6_1_32.js
56 lines (49 loc) · 1.25 KB
/
mandatoryTest_6_1_32.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
import Ajv from 'ajv/dist/jtd.js'
const ajv = new Ajv()
const inputSchema = /** @type {const} */ ({
additionalProperties: true,
properties: {
vulnerabilities: {
elements: {
additionalProperties: true,
properties: {
flags: {
elements: {
additionalProperties: true,
optionalProperties: {
group_ids: { elements: { type: 'string' } },
product_ids: { elements: { type: 'string' } },
},
},
},
},
},
},
},
})
const validate = ajv.compile(inputSchema)
/**
* @param {any} doc
*/
export default function mandatoryTest_6_1_32(doc) {
const ctx = {
errors:
/** @type {Array<{ instancePath: string; message: string }>} */ ([]),
isValid: true,
}
if (!validate(doc)) {
return ctx
}
doc.vulnerabilities.forEach((vulnerability, vulnerabilityIndex) => {
vulnerability.flags.forEach((flag, flagIndex) => {
if (!flag.group_ids && !flag.product_ids) {
ctx.isValid = false
ctx.errors.push({
instancePath: `/vulnerabilities/${vulnerabilityIndex}/flags/${flagIndex}`,
message: 'flag without product reference',
})
}
})
})
return ctx
}