Skip to content

ENH: represent metaschema in LinkML#2350

Draft
yarikoptic wants to merge 16 commits intomasterfrom
enh-linkml-metaschema
Draft

ENH: represent metaschema in LinkML#2350
yarikoptic wants to merge 16 commits intomasterfrom
enh-linkml-metaschema

Conversation

@yarikoptic
Copy link
Copy Markdown
Collaborator

Ongoing work with @effigies and claude code.

yarikoptic and others added 16 commits February 25, 2026 08:40
Covers class hierarchy design, validation continuity, Python/TypeScript
code generation, and CI integration. Scoped to metaschema replacement
only — the BIDS schema YAML files are not modified.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add bids_metaschema.yaml with:
- RequirementLevel enum (required/recommended/optional/deprecated)
- FormatType enum (17 format identifiers matching current metaschema)
- IssueSeverity enum (error/warning)
- GeneralTerm base class (display_name, description)

Also add linkml_design_steps.md with detailed Phase 1 substeps.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add class hierarchy for all BIDS schema object types:
- ValueTerm -> Datatype, Extension, Suffix, EnumValue
- NameValueTerm -> Entity, MetadataField, Column
- Format, FileObject (independent GeneralTerm subclasses)
- PrivateEnum (underscore-prefixed enum definitions)
- JsonSchema (loosely-typed container for embedded JSON Schema)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add rule classes:
- SuffixRule, PathRule, StemRule (file naming rules)
- SidecarRule (JSON sidecar field rules)
- TabularDataRule (TSV column rules)
- CheckRule (validation check rules)
- FieldSpec, EntityOverride (rule sub-components)
- Issue, ErrorDefinition (validation messages)
- ModalityMapping, DirectoryEntry (supporting types)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add meta classes:
- Association + AssociationTarget (file association rules)
- ExpressionTest (expression language test cases)
- Template (reusable partial rule fragments)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add container classes completing the schema structure:
- BidsSchema (tree_root): meta, objects, rules, versions
- MetaSection: associations, context, expression_tests, templates
- ObjectsSection: all 12 object sub-namespace maps
- RulesSection: checks, files, sidecars, tabular_data, etc.
- FileRulesSection: common/raw/deriv file rule groups

Total: 38 LinkML class and enum definitions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add patch_metaschema.py to post-process LinkML-generated JSON Schema,
adding map types (additionalProperties) that LinkML cannot express
natively. Fix Template to allow suffixes/extensions fields.

The pipeline: gen-json-schema | patch_metaschema.py produces a JSON
Schema that successfully validates the compiled BIDS schema, achieving
parity with the existing src/metaschema.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Categorize all 43 JSON Schema patches into 6 groups and analyze how
LinkML's extra_slots feature (not yet implemented in gen-json-schema)
could eliminate most of them once it ships.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Using the draft extra_slots implementation from
sneakers-the-rat/linkml@jsonschema-extra (linkml/linkml#2940),
replace 35 of 43 post-processing patches with native LinkML
declarations:

- Category 4 (8 patches): extra_slots: {allowed: true} on open
  classes (MetadataField, Column, Suffix, etc.)
- Category 1 (16 patches): 13 typed map wrapper classes with
  extra_slots: {range_expression: {range: X}}
- Category 2 (9 patches): 12 nested map wrapper classes
  (CheckRuleGroupMap -> CheckRuleMap -> CheckRule, etc.)
- Category 3 (4 patches): 3 union map classes with any_of in
  range_expression (EntityRequirementMap, FieldRequirementMap, etc.)

Remaining 8 patches: 5 slot-level type coercions, 2 sidecars/
tabular_data derivatives nesting overrides, 1 root $ref.

Key divergence in PR 2940: extra_slots generates spurious
{type: null} in additionalProperties anyOf for class-ranged maps.
This does not break validation but is less strict than intended.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…data dir

- Create gen_class_diagram.py: generates Mermaid classDiagram from
  bids_metaschema.yaml showing 35 data model classes, 3 enums,
  inheritance and composition relationships (excludes 29 map wrappers)
- Create class_diagram.md: auto-generated Mermaid diagram output
- Update linkml_design_plan.md: add Class Hierarchy Diagram section
- Move bids_metaschema.yaml from src/schema/ to src/ to prevent
  _read_yaml_dir from loading it as schema data (broke load_schema)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
while we reviewed rendering of classes diagram
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