Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict JSON Schema validation #1128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading