Skip to content

Other ways to check a record

The Check a record page checks the example record with linkml-validate and check-jsonschema. This page checks it with a short Python script instead. It also shows the files that linkml-validate can't check. Run the commands in the folder and the Python environment from that page's set up section. You need Python 3.11 or newer (https://www.python.org/downloads/).

With Python (jsonschema)

This check uses jsonschema, a JSON Schema library for Python. Download the JSON Schema once, then validate with a short script. Save the script below as validate.py.

pip install "jsonschema[format-nongpl]" pyyaml
curl -sSfL -o midas-catalog.schema.json https://w3id.org/midas-catalog/linkml/schema.json
python validate.py dataset-350.yaml
# validate.py
import json, sys, yaml
from jsonschema import Draft201909Validator

def reasons(e):   # the errors underneath an error, down to the ones with no further cause
    return [r for sub in e.context for r in reasons(sub)] if e.context else [e]

schema = json.load(open("midas-catalog.schema.json"))
validator = Draft201909Validator(schema, format_checker=Draft201909Validator.FORMAT_CHECKER)
errors = validator.iter_errors(yaml.safe_load(open(sys.argv[1])))
found = sorted({("/".join(map(str, r.absolute_path)) or "(root)", r.message) for e in errors for r in reasons(e)})
for where, message in found:
    print(where, ":", message)
print("INVALID" if found else "OK")
sys.exit(1 if found else 0)
OK

The script checks the record against the whole schema. The schema covers every record type, so this check confirms that the record is a valid catalog record, but not which type it is.

When a record fails, the error at the top only says that the record isn't valid as any of the record types. So the script prints the reasons underneath it, once each. For invalid/dataset-350-bad-subject.yaml, it prints:

python validate.py invalid/dataset-350-bad-subject.yaml
about/0/id : 'https://purl.obolibrary.org/obo/DOID_3292' does not match '^(http://purl\\.obolibrary\\.org/obo/|http://w3id\\.org/midas-metadata/|http://edamontology\\.org/|http://www\\.ontodm\\.com/OntoDM-core/|http://vocabs\\.lter-europe\\.net/EnvThes/).+$'
INVALID

For a creator without agentType, as in invalid/dataset-350-no-agenttype.yaml, it prints:

python validate.py invalid/dataset-350-no-agenttype.yaml
creator/0 : 'agentType' is a required property
INVALID

The script turns on format checking (format_checker=…). Without it, jsonschema skips checks such as "this must be a URI", and accepts records that stricter validators reject. The [format-nongpl] extra installs the URI checker. If you install plain jsonschema instead, the format_checker line still runs, but it skips the URI check without an error. A creator url of not-a-web-address then prints OK.

The script reads .jsonld files too, because JSON is valid YAML. So the same command checks a published record.

What linkml-validate can't check

linkml-validate chooses how to read a file from its extension, and it has no reader for .jsonld. It stops with a long Python traceback, and the last line gives the reason:

linkml-validate -s midas-catalog.yaml -C Dataset dataset-350.jsonld 2>&1 | tail -n 1
ValueError: Could not find loader for file: dataset-350.jsonld

To check a JSON-LD file, use check-jsonschema, as on Check a record, or the Python script above.

If you save the record with a .json extension, linkml-validate reads it. But LinkML's JSON reader removes every key that starts with @ before validating. So linkml-validate checks the data and ignores @context and @type. It reports No issues found for invalid/dataset-350-curie-type.jsonld as well.