fix(core): resolve bare $refs before dropping schema definitions - #164
Open
LukasGold wants to merge 1 commit into
Open
fix(core): resolve bare $refs before dropping schema definitions#164LukasGold wants to merge 1 commit into
LukasGold wants to merge 1 commit into
Conversation
- register_schema only rewrote refs reachable via the $..allOf jsonpath - a nested model field without Field() metadata emits a bare $ref - those were left dangling once definitions was deleted - keep definitions when a local ref cannot be resolved - closes #101
Contributor
Release previewMerging this PR would release v2.2.2 (current: Changelog preview (truncated)## v2.2.2 (2026-09-03)
### Bug Fixes
- **core**: Resolve bare $refs before dropping schema definitions
([`9c2ad6e`](https://github.com/OpenSemanticLab/osw-python/commit/9c2ad6e89c31e9b683c039b63eb6472429cbbd76))
Preview via python-semantic-release and conventional commits. |
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.
Closes #101
Problem
OSW.register_schemarewrote only the$refs reachable via the$..allOfjsonpath, then deletedschema["definitions"]unconditionally.pydantic v1 wraps a nested-model
$refinallOfonly when the field carries extra metadata, e.g.Field(description=...). A plain nested field:emits a bare
{"$ref": "#/definitions/Inner"}on the property. Those refs were never rewritten, so deletingdefinitionsleft them dangling.Changes
$..dollarrefinregister_schemathat embeds the local#/definitions/...body in place, mirroring what the existingallOfloop does for wrapped refs.del schema["definitions"]now runs only when every local bare ref resolved, so an unresolvable ref keepsdefinitionsrather than producing a dangling ref.allOfloop is untouched; this is a strict superset of the previous behaviour.Tests
tests/test_register_schema_nested_refs.py, two cases:$ref(noField(...)metadata) is resolved like anallOf-wrapped oneallOf-wrapped ref behaviour is unchangedVerified the first test fails on unpatched code (
AssertionError: assert not Truefrom the dangling-ref check) and passes after the fix. Full unit suite: 170 passed, 1 skipped.Note
Refs nested more than one level deep (a definition that itself holds a bare ref) are resolved in
definitionsbut the already-embedded copy is not re-walked, sincejsonpath.findcollects matches before mutation. The pre-existingallOfloop has the same property, so this PR keeps the behaviour rather than widening scope. Worth a follow-up if such schemas occur in practice.