Skip to content

Commit 2e77fb7

Browse files
authored
fix: JsvonValidator allow arbitrary $schema (#1060)
fixes #1059 --------- Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 52b9878 commit 2e77fb7

File tree

8 files changed

+18
-18
lines changed

8 files changed

+18
-18
lines changed

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
66

77
<!-- add unreleased items here -->
88

9+
* Fixes
10+
* JsonValidator allow arbitrary `$schema` ([#1059] via [#1060])
11+
12+
[#1059]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1059
13+
[#1060]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1060
14+
915
## 6.6.0 -- 2024-04-26
1016

1117
* Changed

res/schema/bom-1.2-strict.SNAPSHOT.schema.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
"additionalProperties": false,
1212
"properties": {
1313
"$schema": {
14-
"type": "string",
15-
"enum": [
16-
"http://cyclonedx.org/schema/bom-1.2b.schema.json"
17-
]
14+
"type": "string"
1815
},
1916
"bomFormat": {
2017
"$id": "#/properties/bomFormat",

res/schema/bom-1.3-strict.SNAPSHOT.schema.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
"additionalProperties": false,
1212
"properties": {
1313
"$schema": {
14-
"type": "string",
15-
"enum": [
16-
"http://cyclonedx.org/schema/bom-1.3a.schema.json"
17-
]
14+
"type": "string"
1815
},
1916
"bomFormat": {
2017
"$id": "#/properties/bomFormat",

res/schema/bom-1.4.SNAPSHOT.schema.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
"additionalProperties": false,
1212
"properties": {
1313
"$schema": {
14-
"type": "string",
15-
"enum": [
16-
"http://cyclonedx.org/schema/bom-1.4.schema.json"
17-
]
14+
"type": "string"
1815
},
1916
"bomFormat": {
2017
"type": "string",

res/schema/bom-1.5.SNAPSHOT.schema.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
"additionalProperties": false,
1212
"properties": {
1313
"$schema": {
14-
"type": "string",
15-
"enum": [
16-
"http://cyclonedx.org/schema/bom-1.5.schema.json"
17-
]
14+
"type": "string"
1815
},
1916
"bomFormat": {
2017
"type": "string",

tests/integration/Validation.JsonStrictValidator.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ describe('Validation.JsonStrictValidator', () => {
8585
it('valid passes', async () => {
8686
const validator = new JsonStrictValidator(version)
8787
const input = JSON.stringify({
88+
$schema: `http://cyclonedx.org/schema/bom-${version}.schema.json`,
8889
bomFormat: 'CycloneDX',
8990
specVersion: version,
9091
components: [{

tests/integration/Validation.JsonValidator.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ describe('Validation.JsonValidator', () => {
8585
it('valid passes', async () => {
8686
const validator = new JsonValidator(version)
8787
const input = JSON.stringify({
88+
$schema: `http://cyclonedx.org/schema/bom-${version}.schema.json`,
8889
bomFormat: 'CycloneDX',
8990
specVersion: version,
9091
components: [{

tools/schema-downloader/download.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ const BomJsonLax = Object.freeze({
5858
replace: Object.freeze([
5959
Object.freeze(['spdx.schema.json', 'spdx.SNAPSHOT.schema.json']),
6060
Object.freeze(['jsf-0.82.schema.json', 'jsf-0.82.SNAPSHOT.schema.json']),
61-
/* fix "$schema" property to match $id */
62-
Object.freeze([/("\$id": "(http:\/\/cyclonedx\.org\/schema\/bom.+?\.schema\.json)".*"enum": \[\s+")http:\/\/cyclonedx\.org\/schema\/bom.+?\.schema\.json"/sg, '$1$2"']),
61+
/* "$schema" is not required but optional.
62+
that enum constraint value there is complicated -> remove it.
63+
See https://github.com/CycloneDX/specification/issues/402
64+
See https://github.com/CycloneDX/specification/pull/403
65+
*/
66+
Object.freeze([/,?\s*"enum"\s*:\s*\[\s*"http:\/\/cyclonedx\.org\/schema\/.+?\.schema\.json"\s*\]/sg, '']),
6367
Object.freeze([_bomRequired, _bomRequiredReplace])
6468
/* there was a case where the default value did not match the own pattern ...
6569
this is wrong in schema<1.5

0 commit comments

Comments
 (0)