Different ways of validating dandiset metadata
- Dominant language
- Python
- Stars
- 28
- Forks
- 37
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 9
Description
i'm doing optional injections only to show other types of errors when known issues are taken into account.
```python
import requests
import json
import jsonschema
def get_dandisets():
url = f"https://api.dandiarchive.org/api/dandisets"
querystring = {"page_size":"100"}
headers = {"Accept": "application/json"}
resp = requests.request("GET", url, headers=headers, params=querystring).json()
results = resp["results"]
while resp["next"]:
resp = requests.request("GET", resp["next"], headers=headers).json()
results.extend(resp["results"])
assert len(results) == resp["count"]
return results
dandisets = get_dandisets()
metadata = {}
for dandiset in dandisets:
url = f"https://api.dandiarchive.org/api/dandisets/{dandiset['identifier']}/versions/draft"
headers = {"Accept": "application/json"}
resp = requests.request("GET", url, headers=headers).json()
metadata[dandiset["identifier"]] = resp
with open("../tmp/schema/0.3.0/dandiset.json") as fp:
schema = json.load(fp)
from dandi.models import DandisetMeta
inject = False # doesn't include some known missing fields
# using model
for val in metadata.values:
base = {}
if inject:
base = dict(version="draft", license=["spdx:CC0-1.0"], contributor=[{"schemaKey": "Person", "name": "Last, First", "roleName": ['dandi:ContactPerson']}], id="fancyid")
base.update(**val)
try:
DandisetMeta(**base)
except ValidationError as e:
print(val["identifier"], str(e))
# using json schema
for val in metadata.values():
base = {}
if inject:
base = dict(version="draft", license=["spdx:CC0-1.0"], contributor=[{"schemaKey": "Person", "name": "Last, First", "roleName": ['dandi:ContactPerson']}], id="fancyid")
base.update(**val)
try:
jsonschema.validate(base, schema)
except jsonschema.ValidationError as e:
print(val["identifier"], e.message)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.