ReproNim / reproschema-py

Apache License 2.0
2 stars 8 forks source link

Update validation to check that file name matches id #43

Open ibevers opened 4 months ago

ibevers commented 4 months ago

From @satra @djarecka : "@id needs to match the filename" "if validation is passing with this, please ask dorota to add that to the validator"

djarecka commented 4 months ago

should this be true for all classes or only for some specific ones, e.g. Item?

satra commented 4 months ago

activity, protocol, and item are the ones that use id dereferencing on github and locally, hence those.

Remi-Gau commented 4 months ago

I had this code snipper lying around on one of my repos if that helps.

import json
import os

tested = 0
for root, _, files in os.walk("schemas", topdown=True):
    for name in files:
        filename = os.path.join(root, name)
        with open(filename) as fp:
            try:
                tested += 1
                data = json.load(fp)
                if data["@id"] and data["@id"] != name:
                    raise ValueError(f"{root}/{name} does not have matching @id")
            except json.decoder.JSONDecodeError:
                print(f"{root}/{name} could not be loaded")
                raise
if tested == 0:
    raise ValueError("Zero files tested")
yibeichan commented 1 month ago

@djarecka did our new reproschema model solve this?