-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Support $ref and $defs in JSON Schema #1030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support $ref and $defs in JSON Schema #1030
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1030 +/- ##
==========================================
+ Coverage 85.83% 86.30% +0.46%
==========================================
Files 43 43
Lines 2316 2387 +71
==========================================
+ Hits 1988 2060 +72
+ Misses 305 302 -3
- Partials 23 25 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
sashabaranov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this is super cool! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds full support for $ref and $defs resolution to the JSON Schema validator, updates schema generation to emit reusable definitions, and extends tests accordingly.
- Implements
CollectDefsto gather all$defsinto a map for lookup - Updates
ValidateandVerifySchemaAndUnmarshalto accept and use resolved definitions - Enhances
GenerateSchemaForTypeand reflection logic to emit$reffor named structs and populate$defs - Adds tests for reference resolution,
$defscollection, and schema generation with$ref/$defs
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| jsonschema/validate.go | Added CollectDefs, extended Validate to handle $ref, and updated VerifySchemaAndUnmarshal to wire in definitions |
| jsonschema/validate_test.go | Added tests for recursive $ref validation and CollectDefs functionality |
| jsonschema/json.go | Extended GenerateSchemaForType and reflection routines to emit $ref/$defs |
| jsonschema/json_test.go | Added schema-generation test verifying $ref and $defs output |
Comments suppressed due to low confidence (1)
jsonschema/validate.go:37
- Unmarshalling into
&vwrites into the local interface variable rather than the caller’s target. Change this tojson.Unmarshal(content, v)so the provided pointer is populated correctly.
return json.Unmarshal(content, &v)
|
@eiixy seems like this PR broke an integration test https://github.com/sashabaranov/go-openai/actions/runs/16192799414/job/45712241252 |
The issue is that using a $ref on the root schema (in a JSON Schema parsing/validation context) breaks proper subschema resolution. I’ll fix this later today—removing the root $ref and updating the parser/validator to align with standard reference resolution. |
* support $ref and $defs in JSON Schema * update
This PR implements $ref and $defs support in the JSON Schema validator.
Key features include: