fix: Allow autopatch to resolve refs, when making the put schema optional - #1080
fix: Allow autopatch to resolve refs, when making the put schema optional#1080lucaspopp-wbd wants to merge 7 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1080 +/- ##
==========================================
+ Coverage 93.22% 93.29% +0.06%
==========================================
Files 23 23
Lines 4976 4997 +21
==========================================
+ Hits 4639 4662 +23
+ Misses 271 269 -2
Partials 66 66 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for this. Two blockers before merge, both reproducible. Stack overflow on recursive schemas. The deref at type Node struct {
Name string `json:"name"`
Children []*Node `json:"children,omitempty"`
}
// register GET + PUT for Node, then AutoPatch(api) => fatal error: stack overflowNil panic on unresolvable refs. makeOptionalSchema(registry, &huma.Schema{Ref: "https://example.com/schemas/Thing.json"})A visited set handles both, matching how if s.Ref != "" {
resolved := registry.SchemaFromRef(s.Ref)
if _, cycle := visited[s.Ref]; cycle || resolved == nil {
// Unresolvable or self-referential: leave the ref in place.
return &huma.Schema{Ref: s.Ref}
}
visited[s.Ref] = struct{}{}
defer delete(visited, s.Ref)
s = resolved
}Keeping the ref on a cycle leaves nested Minor:
|
|
@wolveix all great points! Addressed all of your feedback |
|
Hey @wolveix wondering if you can take another look at this soon? Would love to get this merged in so my team's SDK can leverage this! |
Pass the schema registry to autopatch's
makeOptionalSchemamethod, so it can be leveraged to resolve refs