Skip to content

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

Open
lsdch wants to merge 2 commits intodanielgtaylor:mainfrom
lsdch:field-embed-inline-fix
Open

fix: support json inline tag for embedding anonymous fields in schema#1006
lsdch wants to merge 2 commits intodanielgtaylor:mainfrom
lsdch:field-embed-inline-fix

Conversation

@lsdch
Copy link
Copy Markdown
Contributor

@lsdch lsdch commented Apr 1, 2026

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
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.08%. Comparing base (a38b536) to head (1debcd3).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1006      +/-   ##
==========================================
+ Coverage   93.07%   93.08%   +0.01%     
==========================================
  Files          23       23              
  Lines        4780     4787       +7     
==========================================
+ Hits         4449     4456       +7     
  Misses        271      271              
  Partials       60       60              

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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.

schema.go Outdated
Comment on lines +707 to +709
if jsonTag := f.Tag.Get("json"); jsonTag == "" || jsonTag == ",inline" {
embedded = append(embedded, f)
continue
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

The embedded-field check only treats the JSON tag as inline when it equals exactly ",inline". Struct tags can legally include multiple comma-separated options (e.g. json:",inline,omitempty"), and the rest of this file parses JSON tags by splitting on commas. Consider parsing the tag into name/options and treating the field as embedded when the name part is empty and the options contain inline, so ,inline still works when combined with other options.

Suggested change
if jsonTag := f.Tag.Get("json"); jsonTag == "" || jsonTag == ",inline" {
embedded = append(embedded, f)
continue
if jsonTag := f.Tag.Get("json"); jsonTag == "" {
embedded = append(embedded, f)
continue
} else {
parts := strings.Split(jsonTag, ",")
name := parts[0]
inline := false
for _, opt := range parts[1:] {
if opt == "inline" {
inline = true
break
}
}
if name == "" && inline {
embedded = append(embedded, f)
continue
}

Copilot uses AI. Check for mistakes.
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.

2 participants