Skip to content

Commit ec0e88b

Browse files
committed
run reports on all files
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 6a11336 commit ec0e88b

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

tools/src/test/js/json-schema-lint-tests.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,23 @@ const [spdxSchema, jsfSchema, bomSchemas] = await Promise.all([
2525
assert.notStrictEqual(bomSchemas.length, 0)
2626

2727
/**
28+
* @param {boolean|"log"} strict
2829
* @return {Ajv}
2930
*/
30-
function getAjv() {
31+
function getAjv(strict) {
32+
// see https://ajv.js.org/options.html
3133
const ajv = new Ajv({
32-
// no defaults => no data alteration
33-
useDefaults: false,
34-
// main idea is to be as strict as possible
35-
strict: true,
34+
strict: strict,
35+
strictSchema: strict,
36+
strictNumbers: strict,
37+
strictTypes: strict,
38+
strictTuples: strict,
3639
// this parser has issues with the oneOf-required in
3740
// `{ type: 'object', oneOf:[{required:['a']},{required:['b']}], properties:{a:{...},b:{...}} }`
3841
// so lets simply log them, do not throw errors on them.
39-
strictRequired: 'log',
40-
strictSchema: true,
42+
strictRequired: false,
43+
validateFormats: true,
44+
allowMatchingProperties: true,
4145
addUsedSchema: false,
4246
schemas: {
4347
'http://cyclonedx.org/schema/spdx.schema.json': spdxSchema,
@@ -55,37 +59,36 @@ function getAjv() {
5559
let errCnt = 0
5660

5761
for (const bomSchemaFile of bomSchemas) {
58-
console.log('\nSchemaFile: ', bomSchemaFile);
62+
console.log('\n> SchemaFile: ', bomSchemaFile);
5963
const v = /^bom-(\d)\.(\d)/.exec(basename(bomSchemaFile)) ?? []
6064
if (!v[0]) {
6165
// test match failed
62-
console.log('Skipped.')
63-
continue
64-
}
65-
if (([Number(v[1]), Number(v[2])] < [1, 5])) {
66-
// versions < 1.5 are not expected to pass these tests
67-
console.log('Skipped.')
66+
console.log('> Skipped.')
6867
continue
6968
}
69+
const strict = [Number(v[1]), Number(v[2])] >= [1, 5]
70+
? true
71+
: 'log'
72+
console.debug('> strict:', strict)
7073

7174
let bomSchema
7275
try {
7376
bomSchema = await readFile(bomSchemaFile, 'utf-8').then(JSON.parse)
7477
} catch (err) {
7578
++errCnt
76-
console.error('JSON DECODE ERROR:', err)
79+
console.error('!!! JSON DECODE ERROR:', err)
7780
continue
7881
}
7982

8083
try {
81-
getAjv().compile(bomSchema)
84+
getAjv(strict).compile(bomSchema)
8285
} catch (err) {
8386
++errCnt
84-
console.error(`SCHEMA ERROR: ${err}`)
87+
console.error(`!!! SCHEMA ERROR: ${err}`)
8588
continue
8689
}
8790

88-
console.log('OK.')
91+
console.log('> OK.')
8992
}
9093

9194
// Exit statuses should be in the range 0 to 254.

0 commit comments

Comments
 (0)