fix(goctl): recurse into inline struct in IsTagMember#5671
Open
014-code wants to merge 1 commit into
Open
Conversation
Inline (anonymous-embedded) struct members carry no tag of their own; their tag semantics live on the child members of the referenced struct. IsTagMember previously returned true for any tag key on an inline member, which made tsgen treat every inline struct as having header-tagged fields and emit a spurious headers parameter on the generated TypeScript request function. Recurse into the referenced struct's children for inline members, returning true only when an actual child carries the requested tag. Fixes zeromicro#4800
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
Fix #4800:
goctl api tsgenerates a spurious
headersparameter on TypeScript request functionswhen the request type contains an inline (anonymous-embedded) struct.
Root cause:
Member.IsTagMemberunconditionally returnedtruefor anytag key on an inline member, instead of recursing into the members of
the referenced struct. That made
tsgen.hasRequestHeader(which callsGetTagMembers("header")) treat every inline struct as havingheader-tagged fields and emit a
headersparameter even when theinterface defines no header field at all.
变更内容
tools/goctl/api/spec/fn.goIsTagMembernow first checks the member's own tags.DefineStructorNestedStructreferenced byType.Membersand only returnstruewhen a child actually carries the requested tag.
tools/goctl/api/spec/fn_test.go(new)DefineStruct/NestedStructwith and without matching child tags, nested inline structs, and
the exact When generating TypeScript code, there is an additional headers parameter #4800 scenario via
DefineStruct.GetTagMembers("header").测试
go test ./tools/goctl/api/spec/ -vpre-existing 4 tests in the package.
.apifrom When generating TypeScript code, there is an additional headers parameter #4800 (an inlinePaginationstruct with onlyjsontags) withgo run ./tools/goctl/goctl.go api ts -api demo.api -dir out.The generated
queryUserListfunction now takes onlyreq— thespurious
headersparameter is gone.是否有破坏性变更?
否. The new behavior of
IsTagMemberis consistent with its existingdocstring ("returns true if the member contains the given tag"); an
inline member that carries no matching tag should not have reported
truebefore this fix either. No real consumer relies on the oldalways-
truebehavior — it was the source of the bug itself.Fixes #4800