fix: support json inline tag for embedding anonymous fields in schema#1006
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1006 +/- ##
=======================================
Coverage 93.14% 93.15%
=======================================
Files 23 23
Lines 4905 4906 +1
=======================================
+ Hits 4569 4570 +1
Misses 272 272
Partials 64 64 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Updates schema generation to treat json:",inline" on anonymous (embedded) Go struct fields as an instruction to inline/merge the embedded fields into the parent object schema, matching expectations for redundant-but-valid inline tagging.
Changes:
- Adjust
getFieldsto consider anonymous fields withjson:",inline"as embedded/inlined. - Add a schema test case validating inlining behavior when
json:",inline"is present.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| schema.go | Extends embedded-field detection to include json:",inline" tags. |
| schema_test.go | Adds coverage for the new json:",inline" embedded-field behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hey @lsdch! Would you mind reviewing Copilot's comments, please? :) |
1debcd3 to
9b9c015
Compare
|
Thanks @fredDJSonos for the review ! |
The standard encoding/json marshaler that huma uses by default only inlines anonymous (embedded) fields; a named field tagged with `json:",inline"` is nested under its Go field name, not inlined. Gate the inline handling on f.Anonymous and key off an empty JSON name so the generated schema matches the actual wire format. This also covers `,inline,omitempty` and avoids treating a field literally named "inline" as embedded, while dropping the unused slices import.
Patches #978 to support
json:",inline"tags for embedding anonymous fields.Although a Go embedded field is implicitly inlined, and the presence of this tag on embedded fields is thus redundant, this is still valid syntax and should be supported.