Skip to content

Commit 2eab6bd

Browse files
committed
Enable JSON Schema strict validation
Signed-off-by: Maxime Robert <[email protected]>
1 parent f4cd7b9 commit 2eab6bd

File tree

4 files changed

+107
-3
lines changed

4 files changed

+107
-3
lines changed

package-lock.json

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"@npmcli/arborist": "7.5.2",
7272
"ajv": "^8.14.0",
7373
"ajv-formats": "^3.0.1",
74+
"ajv-formats-draft2019": "^1.6.1",
7475
"cheerio": "^1.0.0-rc.12",
7576
"edn-data": "1.1.1",
7677
"find-up": "7.0.0",

types/validator.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

validator.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { readFileSync } from "node:fs";
22
import { dirname, join } from "node:path";
3+
import { URL, fileURLToPath } from "node:url";
34
import Ajv from "ajv";
45
import addFormats from "ajv-formats";
6+
import addFormatsDraft2019 from "ajv-formats-draft2019";
57
import { PackageURL } from "packageurl-js";
68
import { DEBUG_MODE } from "./utils.js";
79

8-
import { URL, fileURLToPath } from "node:url";
910
let url = import.meta.url;
1011
if (!url.startsWith("file://")) {
1112
url = new URL(`file://${import.meta.url}`).toString();
@@ -35,7 +36,8 @@ export const validateBom = (bomJson) => {
3536
);
3637
const ajv = new Ajv({
3738
schemas: [schema, defsSchema, spdxSchema],
38-
strict: false,
39+
strict: true,
40+
strictRequired: false, // Required as oneOf combined with required is not working well (see https://github.com/ajv-validator/ajv/issues/1571)
3941
logger: false,
4042
verbose: true,
4143
code: {
@@ -45,6 +47,7 @@ export const validateBom = (bomJson) => {
4547
},
4648
});
4749
addFormats(ajv);
50+
addFormatsDraft2019(ajv);
4851
const validate = ajv.getSchema(
4952
`http://cyclonedx.org/schema/bom-${bomJson.specVersion}.schema.json`,
5053
);

0 commit comments

Comments
 (0)