Skip to content

Commit 3f1ab92

Browse files
authored
fix!: VulnerabilityReference all props mandatory (#792)
fixes #790 Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 5853636 commit 3f1ab92

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

Diff for: cyclonedx/model/vulnerability.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -486,43 +486,46 @@ class VulnerabilityReference:
486486
487487
.. note::
488488
See the CycloneDX schema: https://cyclonedx.org/docs/1.6/xml/#type_vulnerabilityType
489+
490+
.. note::
491+
Properties ``id`` and ``source`` are mandatory.
492+
In v1.4 JSON scheme, both properties were mandatory: https://github.com/CycloneDX/specification/blob/d570ffb8956d796585b9574e57598c42ee9de770/schema/bom-1.4.schema.json#L1455-L1474
493+
In v1.4 XML schema, both properties were optional: https://github.com/CycloneDX/specification/blob/d570ffb8956d796585b9574e57598c42ee9de770/schema/bom-1.4.xsd#L1788-L1797
494+
In v1.5 XML schema, both were mandatory: https://github.com/CycloneDX/specification/blob/d570ffb8956d796585b9574e57598c42ee9de770/schema/bom-1.5.xsd#L3364-L3374
495+
Decision: since CycloneDXCoreWorkingGroup chose JSON schema as the dominant schema, the one that serves as first spec implementation, and since XML schema was "fixed" to work same as JSON schema, we'd consider it canon/spec that both properties were always mandatory.
489496
"""
490497

491498
def __init__(
492499
self, *,
493-
id: Optional[str] = None,
494-
source: Optional[VulnerabilitySource] = None,
500+
id: str,
501+
source: VulnerabilitySource,
495502
) -> None:
496-
if not id and not source:
497-
raise NoPropertiesProvidedException(
498-
'Either id or source must be provided for a VulnerabilityReference - neither provided'
499-
)
500503
self.id = id
501504
self.source = source
502505

503506
@property
504507
@serializable.xml_sequence(1)
505508
@serializable.xml_string(serializable.XmlStringSerializationType.NORMALIZED_STRING)
506-
def id(self) -> Optional[str]:
509+
def id(self) -> str:
507510
"""
508511
The identifier that uniquely identifies the vulnerability in the associated Source. For example: CVE-2021-39182.
509512
"""
510513
return self._id
511514

512515
@id.setter
513-
def id(self, id: Optional[str]) -> None:
516+
def id(self, id: str) -> None:
514517
self._id = id
515518

516519
@property
517520
@serializable.xml_sequence(2)
518-
def source(self) -> Optional[VulnerabilitySource]:
521+
def source(self) -> VulnerabilitySource:
519522
"""
520523
The source that published the vulnerability.
521524
"""
522525
return self._source
523526

524527
@source.setter
525-
def source(self, source: Optional[VulnerabilitySource]) -> None:
528+
def source(self, source: VulnerabilitySource) -> None:
526529
self._source = source
527530

528531
def __comparable_tuple(self) -> _ComparableTuple:

0 commit comments

Comments
 (0)