Skip to content

fix: http server codegen#3944

Open
abocim wants to merge 1 commit into
goadesign:v3from
abocim:ab-fix_codegen_server_types
Open

fix: http server codegen#3944
abocim wants to merge 1 commit into
goadesign:v3from
abocim:ab-fix_codegen_server_types

Conversation

@abocim

@abocim abocim commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

This PR fixes a bug we have hit within http server code generator.

Sibling fields in result types were sharing the same AttributeExpr pointer during projection, causing metadata (descriptions and JSON tags) to leak between them. Added field name to the seen key in projectRecursive to be ensured each sibling gets its own isolated entry.

Goa design code:

...
	var UserType = Type("UserType", func() {
		Attribute("u", Int)
	})

	var RT = ResultType("ResultTypeSibling", func() {
		Attribute("a", UserType, "Attribute A", func() {
			Meta("struct:tag:json", "a")
		})
		Attribute("b", UserType, "Attribute B", func() {
			Meta("struct:tag:json", "b")
		})
	})

	Service("ServiceResultUserTypeSibling", func() {
		Method("MethodResultUserTypeSibling", func() {
			Result(RT)
			HTTP(func() {
				GET("/")
			})
		})
	})
...

Incorrectly generated code with leaked descriptions (comments) and JSON tags (gen/http/v2/server/types.go):

...
// MethodResultUserTypeSiblingResponseBody is the type of the
// "ServiceResultUserTypeSibling" service "MethodResultUserTypeSibling"
// endpoint HTTP response body.
type MethodResultUserTypeSiblingResponseBody struct {
	// Attribute A
	A *UserTypeResponseBody `json:"a"`
	// Attribute A
	B *UserTypeResponseBody `json:"a"`
}

// UserTypeResponseBody is used to define fields on response body types.
type UserTypeResponseBody struct {
	U *int `form:"u,omitempty" json:"u,omitempty" xml:"u,omitempty"`
}
...

Sibling fields in result types were sharing the same AttributeExpr pointer
during projection, causing metadata (descriptions and JSON tags) to leak
between them. Added field name to the `seen` key in `projectRecursive`
to be ensured each sibling gets its own isolated entry.

Signed-off-by: Adam Bocim <adam.bocim@seznam.cz>
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.

1 participant