Skip to content

Say in the JSON Schema which slots key a nested list - #35

Merged
jdkent merged 1 commit into
mainfrom
feat/jsonschema-declared-keys
Oct 15, 2026
Merged

jdkent merged 1 commit into
mainfrom
feat/jsonschema-declared-keys

Conversation

@jdkent

@jdkent jdkent commented Oct 15, 2026

Copy link
Copy Markdown
Member

The storage schema declares unique keys for the nested lists a claim path may index, but only in the LinkML YAML. Neurostore keeps its own copy of them (DECLARED_KEYS), and so does its review front end. This is the second of the schema-export PRs, after #34's x-reference.

What changes

  • tools/generate_models.py writes "x-unique-keys": [[slot, ...], ...] on each class with LinkML unique_keys. A class's own keys come first, then those inherited through is_a and mixins. Keys are deduplicated by name, and the nearest declaration wins.
  • study_schema.jsonschema.unique_keys(name) returns {class: ((slot, ...), ...)}, sorted by class.
  • The two annotators share one walk over the classes, _class_definitions. The tests share the generator fixture and a schema-building helper in conftest.py.
  • Only storage-study.schema.json changes, by the added keyword.

Keys (storage-study only; the other schemas declare none)

Class Key
Cell term, level
AnalysisGroup group
ModelTerm name
FactorLevel level

These equal neurostore's DECLARED_KEYS. The test pins them as a golden check of the YAML. Keeping neurostore in sync belongs in neurostore, which will read them through unique_keys("storage-study").

Tests

  • A unit test of the generator on a small LinkML schema covers: own and inherited keys, own before inherited, a redeclared key name with the subclass winning, a mixin's key, two keys on one class, and a class without keys.
  • A shape test covers the helper's order and its tuples.
  • With linkml 1.12, pytest tests passes: 105 passed, 2 skipped (pyarrow and pyarty). generate_models.py --check passes.
  • All 9 mutants of the rule and the helper are killed.

🤖 Generated with Claude Code

The storage schema declares unique keys for the nested lists a claim
path may index (Cell by term and level, AnalysisGroup by group,
ModelTerm by name, FactorLevel by level), but only in the LinkML YAML,
so consumers such as neurostore kept their own copy.

The generator now writes "x-unique-keys": [[slot, ...], ...] on each
class that has unique keys: its own first, then inherited ones from
is_a and mixins, deduplicated by key name with the nearest declaration
winning. study_schema.jsonschema.unique_keys(name) returns them sorted
by class, as tuples. Only storage-study has any.

The generator's two annotators now share one walk over the classes,
and the tests share the generator fixture and a schema-building helper
in conftest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jdkent jdkent left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jdkent
jdkent merged commit ada6c38 into main Oct 15, 2026
4 checks passed
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.

1 participant