#!/usr/bin/env fish

set -l entities freight vehicle route

echo '=== WELL-FORMEDNESS ==='
for entity in $entities
    echo "validating $entity.xml for validity (well-formedness)"
    xmllint --noout "$entity"s.xml
    if test $status -ne 4 # return code 4 - document isn't well-formed
        echo "$entity"s.xml is valid!
    end
end

echo '=== XML SCHEMA COMPLIANCE ==='
for entity in $entities
    echo "validating $entity.xml for compliance with $entity-schema.xsd"
    xmllint --noout --schema $entity-schema.xsd "$entity"s.xml
end

echo '=== JSON SCHEMA COMPLIANCE ==='
for entity in $entities
    echo "validating $entity.json for compliance with $entity-schema.json"
    ajv validate -s "$entity-schema.json" -d "$entity"s.json --spec=draft2020
end
