Skip to content

Commit

Permalink
Enable JSON Schema strict validation
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Robert <maxime.robert@smile.fr>
  • Loading branch information
marob committed May 30, 2024
1 parent df888c3 commit 16d5c71
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 3 deletions.
100 changes: 100 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@npmcli/arborist": "7.5.2",
"ajv": "^8.14.0",
"ajv-formats": "^3.0.1",
"ajv-formats-draft2019": "^1.6.1",
"cheerio": "^1.0.0-rc.12",
"edn-data": "1.1.1",
"find-up": "7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion types/validator.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions validator.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { URL, fileURLToPath } from "node:url";
import Ajv from "ajv";
import addFormats from "ajv-formats";
import addFormatsDraft2019 from "ajv-formats-draft2019";
import { PackageURL } from "packageurl-js";
import { DEBUG_MODE } from "./utils.js";

import { URL, fileURLToPath } from "node:url";
let url = import.meta.url;
if (!url.startsWith("file://")) {
url = new URL(`file://${import.meta.url}`).toString();
Expand Down Expand Up @@ -35,7 +36,8 @@ export const validateBom = (bomJson) => {
);
const ajv = new Ajv({
schemas: [schema, defsSchema, spdxSchema],
strict: false,
strict: true,
strictRequired: false, // Required as oneOf combined with required is not working well (see https://github.com/ajv-validator/ajv/issues/1571)
logger: false,
verbose: true,
code: {
Expand All @@ -45,6 +47,7 @@ export const validateBom = (bomJson) => {
},
});
addFormats(ajv);
addFormatsDraft2019(ajv);
const validate = ajv.getSchema(
`http://cyclonedx.org/schema/bom-${bomJson.specVersion}.schema.json`,
);
Expand Down

0 comments on commit 16d5c71

Please sign in to comment.