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 f84aa82
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 5 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.

4 changes: 2 additions & 2 deletions utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2398,8 +2398,8 @@ test("parsePkgLock v3", async () => {
projectName: "cdxgen",
});
deps = parsedList.pkgList;
expect(deps.length).toEqual(848);
expect(parsedList.dependenciesList.length).toEqual(848);
expect(deps.length).toEqual(859);
expect(parsedList.dependenciesList.length).toEqual(859);
});

test("parseBowerJson", async () => {
Expand Down
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 f84aa82

Please sign in to comment.