Skip to content

Commit 7b5d023

Browse files
committed
xml
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent 24e76fc commit 7b5d023

8 files changed

Lines changed: 114 additions & 8 deletions

schema/bom-1.7.schema.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@
928928
"versionRange": {
929929
"$ref": "#/definitions/versionRange",
930930
"title": "Component Version Range",
931-
"description": "The component version range that may be provided to fulfill this capability.\nMay only occur if `isExtraneous` is `true`."
931+
"description": "The component version range that may be provided to fulfill this capability.\nMAY only occur if `isExtraneous` is `true`."
932932
},
933933
"description": {
934934
"type": "string",
@@ -1116,7 +1116,8 @@
11161116
{
11171117
"$comment": "`version-range` MUST only be present, if `isExtraneous` is `true`",
11181118
"if": { "properties": { "isExtraneous": { "const": false } } },
1119-
"then": { "not": { "required": ["versionRange"] } }
1119+
"then": { "not": { "required": ["versionRange"] } },
1120+
"else": true
11201121
}
11211122
]
11221123
},

schema/bom-1.7.xsd

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,20 @@ limitations under the License.
554554
of the component. Examples: commons-lang3 and jquery</xs:documentation>
555555
</xs:annotation>
556556
</xs:element>
557-
<xs:element name="version" type="bom:versionType" minOccurs="0" maxOccurs="1">
558-
<xs:annotation>
559-
<xs:documentation>The component version. The version should ideally comply with semantic versioning
560-
but is not enforced.</xs:documentation>
561-
</xs:annotation>
562-
</xs:element>
557+
<xs:choice>
558+
<xs:element name="version" type="bom:versionType" minOccurs="0" maxOccurs="1">
559+
<xs:annotation>
560+
<xs:documentation>The component version. The version should ideally comply with semantic versioning
561+
but is not enforced.</xs:documentation>
562+
</xs:annotation>
563+
</xs:element>
564+
<xs:element name="versionRange" type="bom:versionRangeType" minOccurs="0" maxOccurs="1">
565+
<xs:annotation>
566+
<xs:documentation>The component version range that may be provided to fulfill this capability.
567+
MAY only occur if `isExtraneous` is `true`.</xs:documentation>
568+
</xs:annotation>
569+
</xs:element>
570+
</xs:choice>
563571
<xs:element name="description" type="xs:normalizedString" minOccurs="0" maxOccurs="1">
564572
<xs:annotation>
565573
<xs:documentation>Specifies a description for the component</xs:documentation>
@@ -753,12 +761,28 @@ limitations under the License.
753761
</xs:documentation>
754762
</xs:annotation>
755763
</xs:attribute>
764+
<xs:attribute name="isExtraneous" type="xs:boolean" default="false">
765+
<xs:annotation>
766+
<xs:documentation>
767+
Whether this component is extraneous.
768+
An extraneous component is not part of an assembly, but are (expected to be) provided by the environment, regardless of the component's `scope`.
769+
</xs:documentation>
770+
</xs:annotation>
771+
</xs:attribute>
756772
<xs:anyAttribute namespace="##any" processContents="lax">
757773
<xs:annotation>
758774
<xs:documentation>User-defined attributes may be used on this element as long as they
759775
do not have the same name as an existing attribute used by the schema.</xs:documentation>
760776
</xs:annotation>
761777
</xs:anyAttribute>
778+
<!--
779+
this would be formal, if the support for XSD1.1's `assert` was properly implemented
780+
in validators and tools digesting XML.
781+
<xs:assert id="versionRange_requires_isExtraneous_eq_true"
782+
test="if (versionRange) then (@isExtraneous eq 'true') else true()">
783+
child `versionRange` MAY only be present, if attribute `isExtraneous` is `true`
784+
</xs:assert>
785+
-->
762786
</xs:complexType>
763787

764788
<xs:complexType name="licenseType">
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.7"
3+
serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1"
4+
>
5+
<!--
6+
this would be formal, if the support for XSD1.1's `assert` was properly implemented
7+
in validators and tools digesting XML.
8+
-->
9+
<components>
10+
<component type="library" isExtraneous="false">
11+
<name>InvalidVersions</name>
12+
<versionRange><![CDATA[>=9.0.0|<10.0.0]]></versionRange>
13+
<description>versionRange may only exist on extraneous components, set `isExtraneous` explicit</description>
14+
</component>
15+
</components>
16+
</bom>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.7"
3+
serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1"
4+
>
5+
<!--
6+
this would be formal, if the support for XSD1.1's `assert` was properly implemented
7+
in validators and tools digesting XML.
8+
-->
9+
<components>
10+
<component type="library">
11+
<!-- @isExtraneous defaults to `false` -->
12+
<name>InvalidVersions</name>
13+
<versionRange><![CDATA[>=9.0.0|<10.0.0]]></versionRange>
14+
<description>versionRange may only exist on extraneous components, set `isExtraneous` implicit by default value</description>
15+
</component>
16+
</components>
17+
</bom>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.7"
3+
serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1"
4+
>
5+
<components>
6+
<component type="library" isExtraneous="false">
7+
<name>InvalidVersions</name>
8+
<version>9.0.14</version>
9+
<versionRange><![CDATA[>=9.0.0|<10.0.0]]></versionRange>
10+
<description>may have `version` or `versionRange`, not both. This one does - it is invalid</description>
11+
</component>
12+
</components>
13+
</bom>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.7"
3+
serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1"
4+
>
5+
<components>
6+
<component type="library" isExtraneous="true">
7+
<name>Foo</name>
8+
<description>extraneous without any version constraints</description>
9+
</component>
10+
</components>
11+
</bom>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.7"
3+
serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1"
4+
>
5+
<components>
6+
<component type="library" isExtraneous="true">
7+
<name>Foo</name>
8+
<version>9.1.24</version>
9+
<description>extraneous with version constraint</description>
10+
</component>
11+
</components>
12+
</bom>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.7"
3+
serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1"
4+
>
5+
<components>
6+
<component type="library" isExtraneous="true">
7+
<name>Foo</name>
8+
<versionRange><![CDATA[>=9.0.0|<10.0.0]]></versionRange>
9+
<description>extraneous with version range constraints</description>
10+
</component>
11+
</components>
12+
</bom>

0 commit comments

Comments
 (0)