Skip to content

fix: support json inline tag for embedding anonymous fields in schema#1006

Merged
wolveix merged 4 commits into
danielgtaylor:mainfrom
lsdch:field-embed-inline-fix
Jun 18, 2026
Merged

fix: support json inline tag for embedding anonymous fields in schema#1006
wolveix merged 4 commits into
danielgtaylor:mainfrom
lsdch:field-embed-inline-fix

Conversation

@lsdch

@lsdch lsdch commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

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.

Copilot AI review requested due to automatic review settings April 1, 2026 08:33
@codecov

codecov Bot commented Apr 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.15%. Comparing base (34b2d39) to head (6c1d4b1).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 getFields to consider anonymous fields with json:",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.

Comment thread schema.go Outdated
@wolveix

wolveix commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Hey @lsdch! Would you mind reviewing Copilot's comments, please? :)

@lsdch

lsdch commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

Hi @wolveix, I believe I did in 1debcd3
Sorry, I should have added a comment to signal it 😅
Please let me know if the PR still needs fixing

Comment thread schema.go Outdated
@lsdch lsdch force-pushed the field-embed-inline-fix branch from 1debcd3 to 9b9c015 Compare June 6, 2026 21:12
@lsdch

lsdch commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @fredDJSonos for the review !
I used the patch you suggested, and added a test for this case.

wolveix added 3 commits June 18, 2026 23:20
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.
@wolveix wolveix merged commit 93b5a32 into danielgtaylor:main Jun 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants