@@ -90,6 +90,18 @@ export class Factory {
90
90
makeForDependencyGraph ( ) : DependencyGraphNormalizer {
91
91
return new DependencyGraphNormalizer ( this )
92
92
}
93
+
94
+ makeForVulnerability ( ) : VulnerabilityNormalizer {
95
+ return new VulnerabilityNormalizer ( this )
96
+ }
97
+
98
+ makeForVulnerabilitySource ( ) : VulnerabilitySourceNormalizer {
99
+ return new VulnerabilitySourceNormalizer ( this )
100
+ }
101
+
102
+ makeForVulnerabilityReference ( ) : VulnerabilityReferenceNormalizer {
103
+ return new VulnerabilityReferenceNormalizer ( this )
104
+ }
93
105
}
94
106
95
107
const schemaUrl : ReadonlyMap < SpecVersion , string > = new Map ( [
@@ -140,6 +152,9 @@ export class BomNormalizer extends BaseJsonNormalizer<Models.Bom> {
140
152
: [ ] ,
141
153
dependencies : this . _factory . spec . supportsDependencyGraph
142
154
? this . _factory . makeForDependencyGraph ( ) . normalize ( data , options )
155
+ : undefined ,
156
+ vulnerabilities : this . _factory . spec . supportsVulnerabilities && data . vulnerabilities . size > 0
157
+ ? this . _factory . makeForVulnerability ( ) . normalizeIterable ( data . vulnerabilities , options )
143
158
: undefined
144
159
}
145
160
}
@@ -511,6 +526,72 @@ export class DependencyGraphNormalizer extends BaseJsonNormalizer<Models.Bom> {
511
526
}
512
527
}
513
528
529
+ export class VulnerabilityNormalizer extends BaseJsonNormalizer < Models . Vulnerability . Vulnerability > {
530
+ normalize ( data : Models . Vulnerability . Vulnerability , options : NormalizerOptions ) : Normalized . Vulnerability | undefined {
531
+ const source = data . source !== undefined
532
+ ? this . _factory . makeForVulnerabilitySource ( ) . normalize ( data . source , options )
533
+ : undefined
534
+ const references = data . references . size > 0
535
+ ? this . _factory . makeForVulnerabilityReference ( ) . normalizeIterable ( data . references , options )
536
+ : undefined
537
+
538
+ return {
539
+ id : data . id ,
540
+ source,
541
+ references,
542
+ description : data . description ,
543
+ detail : data . detail ,
544
+ recommendation : data . recommendation ,
545
+ created : data . created ,
546
+ published : data . published ,
547
+ updated : data . updated
548
+ }
549
+ }
550
+
551
+ normalizeIterable ( data : SortableIterable < Models . Vulnerability . Vulnerability > , options : NormalizerOptions ) : Normalized . Vulnerability [ ] {
552
+ return (
553
+ options . sortLists ?? false
554
+ ? data . sorted ( )
555
+ : Array . from ( data )
556
+ ) . map (
557
+ c => this . normalize ( c , options )
558
+ ) . filter ( isNotUndefined )
559
+ }
560
+ }
561
+
562
+ export class VulnerabilitySourceNormalizer extends BaseJsonNormalizer < Models . Vulnerability . Source > {
563
+ normalize ( data : Models . Vulnerability . Source , options : NormalizerOptions ) : Normalized . VulnerabilitySource {
564
+ const url = data . url !== undefined && typeof data . url !== 'string'
565
+ ? data . url . toString ( )
566
+ : data . url
567
+ return {
568
+ name : data . name ,
569
+ url
570
+ }
571
+ }
572
+ }
573
+
574
+ export class VulnerabilityReferenceNormalizer extends BaseJsonNormalizer < Models . Vulnerability . Reference > {
575
+ normalize ( data : Models . Vulnerability . Reference , options : NormalizerOptions ) : Normalized . VulnerabilityReference {
576
+ return {
577
+ id : data . id ,
578
+ source : data . source !== undefined
579
+ ? this . _factory . makeForVulnerabilitySource ( ) . normalize ( data . source , options )
580
+ : undefined
581
+ }
582
+ }
583
+
584
+ normalizeIterable ( data : SortableIterable < Models . Vulnerability . Reference > , options : NormalizerOptions ) : Normalized . VulnerabilityReference [ ] {
585
+ return (
586
+ options . sortLists ?? false
587
+ ? data . sorted ( )
588
+ : Array . from ( data )
589
+ ) . map (
590
+ c => this . normalize ( c , options )
591
+ ) . filter ( isNotUndefined )
592
+ }
593
+ }
594
+
514
595
/* eslint-enable @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions */
515
596
516
597
function normalizeStringableIter ( data : Iterable < Stringable > , options : NormalizerOptions ) : string [ ] {
0 commit comments