Skip to content
Snippets Groups Projects
Commit b49d5e6a authored by vlorentz's avatar vlorentz
Browse files

Enforce create_origin/add_to_origin/reference are mutually exclusive in the schema

parent e0879560
No related branches found
No related tags found
No related merge requests found
......@@ -367,6 +367,84 @@ _parameters4 = [
"fields": ["swh:deposit"],
},
),
(
f"""\
<entry {XMLNS}>
<url>something</url>
<external_identifier>something-else</external_identifier>
<title>bar</title>
<author>someone</author>
<swh:deposit>
<swh:add_to_origin>
<swh:origin url="http://example.org" />
</swh:add_to_origin>
<swh:create_origin>
<swh:origin url="http://example.org" />
</swh:create_origin>
</swh:deposit>
</entry>
""",
{
"summary": (
r".*Reason: assertion test if false.*"
r"Schema:\n*"
r' *<xsd:assert[^>]+ id="swhdeposit-incompatible-create-and-add".*'
),
"fields": ["swh:deposit"],
},
),
(
f"""\
<entry {XMLNS}>
<url>something</url>
<external_identifier>something-else</external_identifier>
<title>bar</title>
<author>someone</author>
<swh:deposit>
<swh:create_origin>
<swh:origin url="http://example.org" />
</swh:create_origin>
<swh:reference>
<swh:origin url="http://example.org" />
</swh:reference>
</swh:deposit>
</entry>
""",
{
"summary": (
r".*Reason: assertion test if false.*"
r"Schema:\n*"
r' *<xsd:assert[^>]+ id="swhdeposit-incompatible-create-and-reference".*'
),
"fields": ["swh:deposit"],
},
),
(
f"""\
<entry {XMLNS}>
<url>something</url>
<external_identifier>something-else</external_identifier>
<title>bar</title>
<author>someone</author>
<swh:deposit>
<swh:add_to_origin>
<swh:origin url="http://example.org" />
</swh:add_to_origin>
<swh:reference>
<swh:origin url="http://example.org" />
</swh:reference>
</swh:deposit>
</entry>
""",
{
"summary": (
r".*Reason: assertion test if false.*"
r"Schema:\n*"
r' *<xsd:assert[^>]+ id="swhdeposit-incompatible-add-and-reference".*'
),
"fields": ["swh:deposit"],
},
),
(
f"""\
<entry {XMLNS}>
......
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
targetNamespace="https://www.softwareheritage.org/schema/2018/deposit"
xmlns:swh="https://www.softwareheritage.org/schema/2018/deposit"
elementFormDefault="qualified"
......@@ -7,9 +8,6 @@
<xsd:element name="deposit">
<xsd:complexType>
<xsd:all>
<!-- note that "create_origin", "add_to_origin", and "reference" are
mutually exclusive -->
<!-- code deposit on a new origin -->
<xsd:element name="create_origin" minOccurs="0">
<xsd:complexType>
......@@ -47,6 +45,23 @@
</xsd:element>
</xsd:all>
<!-- "create_origin", "add_to_origin", and "reference" are mutually exclusive. -->
<xsd:assert
id="swhdeposit-incompatible-create-and-add"
test="not(swh:create_origin) or not(swh:add_to_origin)"
vc:minVersion="1.1"
/>
<xsd:assert
id="swhdeposit-incompatible-create-and-reference"
test="not(swh:create_origin) or not(swh:reference)"
vc:minVersion="1.1"
/>
<xsd:assert
id="swhdeposit-incompatible-add-and-reference"
test="not(swh:add_to_origin) or not(swh:reference)"
vc:minVersion="1.1"
/>
</xsd:complexType>
</xsd:element>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment