fix(v2): preserve nested struct JSON structure for embedded types with json tags#5213
fix(v2): preserve nested struct JSON structure for embedded types with json tags#5213leaanthony wants to merge 1 commit into
Conversation
…h json tags When a Go struct has anonymous embedded struct fields with explicit json tags (e.g., `TimeLimitDef `json:"timeLimitDef"``), Go's encoding/json marshals them as nested objects. However, the TS binding generator unconditionally flattened these fields, producing incorrect TypeScript that couldn't deserialize the JSON. Fix deepFields() in typescriptify to check for json tags on anonymous fields before flattening. Fix AddStructToGenerateTS() in binding.go to register embedded struct types with json tags for separate TS class generation. Fixes #4117
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🤖 PR Triage Review ✅ Accepted Preserves nested struct JSON structure for embedded types with json tags (v2 bindings). Improves JSON handling. Platform: All (v2, bindings) Next Steps: Dispatching for testing on all platforms. Reviewed by Wails PR Reviewer Bot |
Summary
Fixes #4117
When a Go struct has anonymous embedded struct fields with explicit json tags (e.g.,
TimeLimitDef \json:"timeLimitDef"`), Go'sencoding/json` marshals them as nested objects. However, the TS binding generator unconditionally flattened these fields, producing incorrect TypeScript that couldn't deserialize the JSON.Changes
deepFields()intypescriptify.go: Check for json tags on anonymous fields before flattening. If an anonymous field has an explicit json tag name, treat it as a regular struct field.AddStructToGenerateTS()inbinding.go: Register embedded struct types with json tags for separate TS class generation instead of skipping them.binding_embedded_named_struct_jsontag_test.gothat reproduces the exact scenario from the bug report.Before (buggy)
After (fixed)
Test plan
EmbeddedNamedStructJSONTagTestpasses with correct nested output