Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve _validate_obj_json() in metadata.py and provide utility funcs for validating against JSON schemas #278

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

candleindark
Copy link
Member

@candleindark candleindark commented Jan 29, 2025

This PR make the following improvement relating to validating metadata instances against a DANDI model's JSON schema.

  1. Define a utility function, `jsonschema_validator(), for creating an appropriate JSON schema validator given a schema.
    1. Ensure validity of the schema is checked to ensure to prevent undefined behavior. (A bug fix)
    2. Utilized the "$schema" property in a provide schema to determine the appropriate validator class
  2. Define a utility function, validate_json(), to validate a metadata instance of a DANDI model against the JSON schema of the model.
    1. Decide the default/fallback validator class to used based on the "schemaVersion" property of the given schema instead of the "schemaVersion" field of a given instance. (A bug fix)
  3. Reimplement _validate_obj_json() using the aforementioned utility functions and provide tests

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.83%. Comparing base (6fd04fb) to head (d4d802f).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #278      +/-   ##
==========================================
- Coverage   97.54%   92.83%   -4.71%     
==========================================
  Files          16       16              
  Lines        1753     1885     +132     
==========================================
+ Hits         1710     1750      +40     
- Misses         43      135      +92     
Flag Coverage Δ
unittests 92.83% <100.00%> (-4.71%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@candleindark candleindark marked this pull request as draft January 31, 2025 08:47
@candleindark candleindark added the bug Something isn't working label Jan 31, 2025
@candleindark candleindark marked this pull request as ready for review January 31, 2025 17:02
@candleindark candleindark changed the title Improve _validate_obj_json() in metadata.py and provide utility funcs for validating with JSON schema Improve _validate_obj_json() in metadata.py and provide utility funcs for validating against JSON schemas Jan 31, 2025
A util func for validating a metadata
instance of a DANDI model against the
JSON schema of the model
Additionally, replace relative import
with absolute import in `test_util.py`
The relative import was referring to
an ancestor. See https://docs.astral.sh/ruff/rules/relative-imports/
Improve type annotations. Make boolean
parameter keyword parameter. Make it
more correct and robust by using
`validate_json()` underneath.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant