Repository navigation
Write JSON Schema properties in the LinkML's declared order - #45
Merged
Merged
Conversation
The generated JSON Schemas listed properties alphabetically: LinkML's serialize() and tools/generate_models.py both sorted keys. Consumers that show a class's fields in schema order (neurostore's review app) got age_sd far from age_mean. render() now takes the generator's dict and sorts every key except each object's properties, which keep the induced slot order. The regenerated schemas load equal to the old ones; only property order changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The generated JSON Schemas list each class's properties alphabetically. The LinkML declares a deliberate order: Group, for example, keeps the counts together, then the criteria, then
age_mean,age_standard_deviation,age_minimum,age_maximum,age_median,age_unit. Consumers that show fields in schema order lose it. neurostore's review app scattered the age fields across the card.The order was lost in two places:
JsonSchemaGenerator.serialize()dumps withsort_keys=True;tools/generate_models.pysorts again.Changes
render()takes the generator's dict (generate().to_json()) and sorts every key except each object'sproperties, which keep LinkML's induced slot order: parent slots first, sostable_idandlocal_idlead.$defs, top-level keys and each property's own keys stay sorted, so diffs stay stable.==) to the previous version; only property order changes.tests/test_declared_order.py: every class's properties in all four schemas followSchemaView.class_induced_slots, and generation is deterministic.The Pydantic models are unchanged. Their field order differs from the LinkML in a few classes (the modality and
*Detailsclasses putstable_id/local_idordetails_typefirst), which nothing reads by position.The diff is large (+4887/−4874) but is reordering only. If #43 or #44 regenerate the schemas, they'll conflict here; regenerating after merging resolves it.
🤖 Generated with Claude Code