If a field is exported, generate json even in the absence of tags#3678
Conversation
WalkthroughThe recent changes improve the handling of exported fields in JSON serialization and TypeScript generation from Go structs. Key modifications include adding checks for the presence of "json" tags in exported fields, ensuring that fields without tags are correctly recognized and named. This addresses previous issues related to model generation for output types, enhancing the functionality and usability of the binding mechanism. Changes
Sequence Diagram(s)sequenceDiagram
participant GoStruct
participant JSONSerializer
participant TypeScriptGenerator
GoStruct->>JSONSerializer: Check for exported fields
JSONSerializer->>GoStruct: Identify exported fields without "json" tag
GoStruct->>TypeScriptGenerator: Generate model from Go struct
TypeScriptGenerator->>TypeScriptModel: Create TypeScript definition with field names
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- v2/internal/binding/binding.go (1 hunks)
- v2/internal/typescriptify/typescriptify.go (1 hunks)
Additional comments not posted (2)
v2/internal/binding/binding.go (1)
353-355: Ensure exported fields without JSON tags are correctly handled.The logic now considers exported fields without JSON tags as having exported JSON fields. This change aligns with the PR objectives to generate TypeScript models for such fields.
v2/internal/typescriptify/typescriptify.go (1)
556-562: Handle exported fields without JSON tags and mark optional fields.The method now names exported fields without JSON tags based on their field name and appends a question mark for optional fields. This change improves TypeScript definition generation.
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- v2/internal/binding/binding_test/binding_notags_test.go (1 hunks)
- v2/internal/binding/binding_test/binding_test.go (1 hunks)
Additional comments not posted (3)
v2/internal/binding/binding_test/binding_notags_test.go (2)
3-8: StructNoFieldTagsis well-defined.The struct
NoFieldTagsis a straightforward representation of a Go struct without JSON tags, which aligns with the purpose of the test.
14-59: Test caseNoFieldTagsTestis comprehensive.The test case
NoFieldTagsTesteffectively verifies the TypeScript model generation for structs without JSON tags. The expected TypeScript output is clearly defined, and the test covers various field types, including pointers and nested structs.v2/internal/binding/binding_test/binding_test.go (1)
53-53: Integration ofNoFieldTagsTestenhances test coverage.The addition of
NoFieldTagsTestto theTestBindings_GenerateModelsfunction improves the test coverage by validating the model generation for structs without JSON tags. This aligns with the PR objectives and ensures robust functionality.
|
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- website/src/pages/changelog.mdx (1 hunks)
Additional comments not posted (1)
website/src/pages/changelog.mdx (1)
22-22: Changelog entry is clear and informative.The entry provides a concise description of the fix and references the associated pull request, ensuring traceability.
…ilsapp#3678) * if no JSON tag, check if field is exported * add no-tags binding test case * update changelog for wailsapp#3678



Description
Fixes #945 - generate typescript models for structs that do not contain json tags, using similar logic as Go's JSON interfaces (e.g. in the absence of json tags, if the field is exported then include it as-is).
Type of change
How Has This Been Tested?
I'm not sure the "proper" way to test, but I vendored wails in my app with these changes and looked at the resulting
models.tsoutput.Test Configuration
For brevity I will skip
wails doctoroutput here but I can include if necessary.Checklist:
website/src/pages/changelog.mdxwith details of this PRSummary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests