Establish central API to validate metadata record for a given schema version
- Dominant language
- Python
- Stars
- 7
- Forks
- 15
- PR merge metrics
- No merged PRs in 30d
Description
It is ongoing discussion on how we should/could do that, e.g. could be
- upgrade provided metadata to the most recent pydantic model version and validate against pydantic model
- use exported jsonschema + ad-hoc set of rules to be enforced in addition (not supported by jsonschema)
- ...
and then we need to decide on the return value from the validation helper.
- simple pythonic: successful run just returns, failed validation raises ValidationError exception which would contain details of validation errors. Cons:
- no way to report "warnings"
- no feedback from helper on what was actually validated
- just return a list of validation results (`ValidationResult` base class, could get more specialized into `NWBValidationResult` etc) per each "item" (dandiset or asset), consisting of records or structures with `valid: bool | None` where `None` (or Ellipsis?) for cases where failed to load/validate so cannot state on validity, and also `errors: list` and `warnings: list`. Cons:
- would need a helper like `all(r['valid'] for r in results)` for every point of invocation to make a judgement on overall validity.
- Could be mitigated if returned structure (`ValidationResults`?) is list (or dict for lookup by path?) based interface with `.all_valid` helper property which would accomplish that. We could even get `.valid` and `.invalid` helpers. Also `.errors` and `.warnings` which would group all detected errors and warnings across files: it would be valuable for reporting to the user without flooding the screen per each item. `__str__` of the `ValidationResults` could provide a summary (e.g. `validation failed. 10 unique errors across 30 files`) and have `.print` or alike to provide ad-hoc print out of all gory details.
Then we could do smth like
```python
r = validate(path, schema_version='0.3.1')
if not r.valid:
print(f"Validation failed: {r}")
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.