Skip to content

Update class inheritance to support multi-parent schemas (biothings/discovery-app#330)#23

Merged
NikkiBytes merged 13 commits intomasterfrom
update_class_inheritance
Aug 21, 2025
Merged

Update class inheritance to support multi-parent schemas (biothings/discovery-app#330)#23
NikkiBytes merged 13 commits intomasterfrom
update_class_inheritance

Conversation

@NikkiBytes
Copy link
Contributor

@NikkiBytes NikkiBytes commented Aug 8, 2025

Enhance parent validation merging with support for multi-inheritance and list merging

This update improves the recursive parent validation logic in validator.py:

  • Supports multiple rdfs:subClassOf parents (previously only a single parent was handled).
  • Introduces visited tracking to prevent cyclic recursion or duplicate merging.
  • Updates merge() to combine lists (e.g., merging "required" fields across parents), instead of skipping or overwriting them.
  • Ensures more complete and accurate schema validation when multiple parents define validation logic.

These changes enable the system to correctly handle complex ontologies with multi-inheritance and overlapping validation fields.

@NikkiBytes
Copy link
Contributor Author

Notes on Validator Enhancements (biothings_schema/validator.py)

  • New _norm_id method

    • Strips whitespace.
    • Expands CURIEs using known prefixes.
    • Normalizes schema.org variants (httphttps and www removal).
    • Ensures consistent trailing slash removal.
  • New _merge_lists method

    • Merges lists with de-duplication.
    • Handles complex list items (dict/list) using JSON serialization for uniqueness.
  • Enhanced merge method

    • Supports merging nested dictionaries.
    • Uses _merge_lists for merging list values.
    • Performs deep copies to avoid shared mutable references.
  • Refactored merge_recursive_parents

    • Now handles multiple inheritance (rdfs:subClassOf as list or dict).
    • Tracks visited parent IDs to prevent infinite loops.
    • Normalizes IDs before lookup to ensure http/https and CURIE consistency.
    • Recurses cleanly up the class hierarchy, merging $validation fields from all ancestors.

…ta, extended test_schema_validatior with tests for validation merging and extended test_bioschemas with multi-inheritances tests
…ed test_bioschemas.py back to use that data, and modified for empty list of lists
@NikkiBytes NikkiBytes merged commit 9ee121e into master Aug 21, 2025
8 checks passed
@NikkiBytes NikkiBytes deleted the update_class_inheritance branch December 15, 2025 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants