Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/scripts/validate-should-fail.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# Negative examples: documents that MUST be rejected by the schema.
# Each case greps the EXACT expected constraint name, so dropping that constraint
# (document wrongly accepted) fails the build and can't be masked by another error.

set -u
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ROOT_DIR=$( cd -- "${SCRIPT_DIR}/../.." &> /dev/null && pwd )
# CI uses the vendored 2025 Linux x86-64 xmllint ("Temporary xmllint master",
# https://github.com/TransmodelEcosystem/NeTEx/pull/915); set XMLLINT_BIN to a local
# xmllint to run this on any other OS or CPU architecture (macOS, Windows, ARM, ...).
XMLLINT="${XMLLINT_BIN:-${SCRIPT_DIR}/xmllint}"
cd "${ROOT_DIR}"

fail=0
assert_rejected() { # <file> <schema> <error-pattern>
if "${XMLLINT}" --noout --schema "$2" "$1" 2>&1 | grep -q "$3"; then
echo "OK $1"
else
echo "SHOULD HAVE FAILED $1 — not rejected by '$3' (constraint missing?)"
fail=1
fi
}

echo "Checking NeTEx 'should-fail' negative examples ..."
assert_rejected examples/should-fail/duplicate-GroupOfLinkSequences.xml xsd/NeTEx_publication.xsd GroupOfLinkSequences_UniqueBy_Id_Version

exit "${fail}"
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: Validate NeTEx XML examples
run: ./.github/scripts/validate-examples.sh

- name: Validate negative examples (must-fail)
run: ./.github/scripts/validate-should-fail.sh

- name: Commit changes
uses: EndBug/add-and-commit@v9 # https://github.com/marketplace/actions/add-commit
with:
Expand Down
7 changes: 7 additions & 0 deletions examples/should-fail/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Negative examples (must-fail)

Each file carries one deliberate defect and must therefore be **rejected** by the
schema for a specific, expected reason. The cases — file, schema and expected
constraint — are declared in `.github/scripts/validate-should-fail.sh` (run in CI).

Run locally: `XMLLINT_BIN=$(which xmllint) ./.github/scripts/validate-should-fail.sh`
13 changes: 13 additions & 0 deletions examples/should-fail/duplicate-GroupOfLinkSequences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<PublicationDelivery xmlns="http://www.netex.org.uk/netex" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<PublicationTimestamp>2020-01-01T12:00:00Z</PublicationTimestamp>
<ParticipantRef>TEST</ParticipantRef>
<dataObjects>
<ResourceFrame version="1.0" id="TEST:ResourceFrame:1">
<groupsOfEntities>
<GroupOfLinkSequences version="1.0" id="TEST:GroupOfLinkSequences:1"/>
<GroupOfLinkSequences version="1.0" id="TEST:GroupOfLinkSequences:1"/>
</groupsOfEntities>
</ResourceFrame>
</dataObjects>
</PublicationDelivery>
9 changes: 9 additions & 0 deletions xsd/NeTEx_publication.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,15 @@
<xsd:field xpath="@version"/>
</xsd:key>
<!-- =====GroupOfLinkSequences============================== -->
<!-- =====GroupOfLinkSequences unique========================== -->
<xsd:unique name="GroupOfLinkSequences_UniqueBy_Id_Version">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think this is correct? For example, why isn't this just a key?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See PR description (just added) ; I think it's more correct that what is in #998 on that specific bit, which was effectively removal of any sort of uniqueness check.

Why not key, well, key has been removed before v2.0.0 (see description). I don't know if adding it back in a patch release is a good idea or not, we'll have to discuss that collectively.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thbar and @skinkie,
I confirm that in v1.3, this part was written as follow:

		<!-- =====GroupOfLinkSequences============================== -->
		<!-- =====GroupOfLinkSequences unique========================== -->
		<xsd:unique name="GroupOfLinkSequences_UniqueBy_Id_Version">
			<xsd:annotation>
				<xsd:documentation>Every [GroupOfLinkSequences Id + Version] must be unique within document.</xsd:documentation>
			</xsd:annotation>
			<xsd:selector xpath=".//netex:GroupOfLinkSequences"/>
			<xsd:field xpath="@id"/>
			<xsd:field xpath="@version"/>
		</xsd:unique>

Direct link is this one.

Considering that GroupOfLinkSequencesRef is based on the substitution group VersionOfObjectRef and not TypeOfEntityRef, I am uncertain that a key will work.

However, let's make it simple and roll back to the original state of this part of the XSD.

<xsd:annotation>
<xsd:documentation>Every [GroupOfLinkSequences Id + Version] must be unique within document.</xsd:documentation>
</xsd:annotation>
<xsd:selector xpath=".//netex:GroupOfLinkSequences"/>
<xsd:field xpath="@id"/>
<xsd:field xpath="@version"/>
</xsd:unique>
<!-- =====SimpleFeature============================== -->
<!-- =====SimpleFeature Key ========================== -->
<xsd:keyref name="SimpleFeature_KeyRef" refer="netex:SimpleFeature_AnyVersionedKey">
Expand Down
Loading