ci(xml): xml validation
This commit is contained in:
parent
45c8f23097
commit
0379a3ccff
3 changed files with 92 additions and 1 deletions
63
data/schema/template.xsd
Normal file
63
data/schema/template.xsd
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
|
||||||
|
<xs:element name="template">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="description" type="xs:string" />
|
||||||
|
<xs:element name="record" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="preamble" type="xs:string" minOccurs="0" />
|
||||||
|
<xs:element name="note" type="xs:string" minOccurs="0" />
|
||||||
|
<xs:element name="field" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="option" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="value" type="xs:string" use="required" />
|
||||||
|
<xs:attribute name="label" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="label" type="xs:string" use="required" />
|
||||||
|
<xs:attribute name="type" type="fieldType" use="required" />
|
||||||
|
<xs:attribute name="required" type="xs:boolean" />
|
||||||
|
<xs:attribute name="placeholder" type="xs:string" />
|
||||||
|
<xs:attribute name="from" type="xs:string" />
|
||||||
|
<xs:attribute name="min" type="xs:decimal" />
|
||||||
|
<xs:attribute name="max" type="xs:decimal" />
|
||||||
|
<xs:attribute name="unit" type="xs:string" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="type" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="name" type="xs:string" use="required" />
|
||||||
|
<xs:attribute name="schemaVersion" type="xs:positiveInteger" use="required" />
|
||||||
|
<xs:attribute name="species" type="xs:string" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:simpleType name="fieldType">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="text" />
|
||||||
|
<xs:enumeration value="textarea" />
|
||||||
|
<xs:enumeration value="list" />
|
||||||
|
<xs:enumeration value="number" />
|
||||||
|
<xs:enumeration value="select" />
|
||||||
|
<xs:enumeration value="multi-select" />
|
||||||
|
<xs:enumeration value="checkbox" />
|
||||||
|
<xs:enumeration value="date" />
|
||||||
|
<xs:enumeration value="height" />
|
||||||
|
<xs:enumeration value="weight" />
|
||||||
|
<xs:enumeration value="species" />
|
||||||
|
<xs:enumeration value="subspecies" />
|
||||||
|
<xs:enumeration value="citizenship" />
|
||||||
|
<xs:enumeration value="languages" />
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
|
||||||
|
</xs:schema>
|
||||||
|
|
@ -9,7 +9,8 @@
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"prepare": "svelte-kit sync || echo ''",
|
"prepare": "svelte-kit sync || echo ''",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||||
|
"validate": "scripts/validate-xml.sh"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "^7.0.0",
|
"@sveltejs/adapter-auto": "^7.0.0",
|
||||||
|
|
|
||||||
27
scripts/validate-xml.sh
Executable file
27
scripts/validate-xml.sh
Executable file
|
|
@ -0,0 +1,27 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
schema_dir="data/schema"
|
||||||
|
fail=0
|
||||||
|
|
||||||
|
validate() {
|
||||||
|
local schema="$1" file="$2"
|
||||||
|
if xmllint --noout --schema "$schema" "$file" 2>&1; then
|
||||||
|
:
|
||||||
|
else
|
||||||
|
fail=1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
for f in data/species/*.xml; do
|
||||||
|
validate "$schema_dir/species.xsd" "$f"
|
||||||
|
done
|
||||||
|
|
||||||
|
validate "$schema_dir/citizenships.xsd" data/citizenships.xml
|
||||||
|
validate "$schema_dir/languages.xsd" data/languages.xml
|
||||||
|
|
||||||
|
for f in data/templates/*.xml; do
|
||||||
|
validate "$schema_dir/template.xsd" "$f"
|
||||||
|
done
|
||||||
|
|
||||||
|
exit $fail
|
||||||
Loading…
Add table
Add a link
Reference in a new issue