Repository: goadesign/goa
Pull request #3712 (2025-05-23 00:59:20)

bug: fix support for streaming aliased array types
 with custom package paths


Patch:
diff --git a/expr/http_body_types.go b/expr/http_body_types.go
index ea1edf25..5bd4cc2d 100644
--- a/expr/http_body_types.go
+++ b/expr/http_body_types.go
@@ -227,12 +227,14 @@ func httpStreamingBody(e *HTTPEndpointExpr) *AttributeExpr {
 		return DupAtt(att)
 	}
 	const suffix = "StreamingBody"
+	dupped := DupAtt(att)
+	RemovePkgPath(dupped)
+	appendSuffix(dupped.Type, suffix)
 	ut := &UserTypeExpr{
-		AttributeExpr: DupAtt(att),
+		AttributeExpr: dupped,
 		TypeName:      concat(e.Name(), "Streaming", "Body"),
 		UID:           e.Service.Name() + "#" + e.Name() + "StreamingBody",
 	}
-	appendSuffix(ut.Attribute().Type, suffix)
 
 	return &AttributeExpr{
 		Type:         ut,


Test patch:
diff --git a/http/codegen/client_body_types_test.go b/http/codegen/client_body_types_test.go
index 1abad7d8..4504348f 100644
--- a/http/codegen/client_body_types_test.go
+++ b/http/codegen/client_body_types_test.go
@@ -52,6 +52,7 @@ func TestBodyTypeInit(t *testing.T) {
 		{"result-explicit-body-user-type", testdata.ExplicitBodyUserResultMultipleViewsDSL, 3, ExplicitBodyUserResultMultipleViewsInitCode},
 		{"result-explicit-body-object", testdata.ExplicitBodyUserResultObjectDSL, 3, ExplicitBodyObjectInitCode},
 		{"result-explicit-body-object-views", testdata.ExplicitBodyUserResultObjectMultipleViewDSL, 3, ExplicitBodyObjectViewsInitCode},
+		{"body-streaming-aliased-array", testdata.StreamingAliasedArrayDSL, 4, StreamingAliasedArrayBodyInitCode},
 	}
 	for _, c := range cases {
 		t.Run(c.Name, func(t *testing.T) {
@@ -279,6 +280,21 @@ func NewMethodExplicitBodyUserResultObjectMultipleViewResulttypemultipleviewsOK(
 	return v
 }
 `
+
+const StreamingAliasedArrayBodyInitCode = `// NewStreamStreamingBody builds the HTTP request body from the payload of the
+// "Stream" endpoint of the "StreamingAliasedArray" service.
+func NewStreamStreamingBody(p *streamingaliasedarray.PayloadType) *StreamStreamingBody {
+	body := &StreamStreamingBody{}
+	if p.Values != nil {
+		body.Values = make([]CustomIntStreamingBody, len(p.Values))
+		for i, val := range p.Values {
+			body.Values[i] = CustomIntStreamingBody(val)
+		}
+	}
+	return body
+}
+`
+
 const MixedPayloadInBodyClientTypesFile = `// MethodARequestBody is the type of the "ServiceMixedPayloadInBody" service
 // "MethodA" endpoint HTTP request body.
 type MethodARequestBody struct {
diff --git a/http/codegen/testdata/streaming_aliased_array_dsls.go b/http/codegen/testdata/streaming_aliased_array_dsls.go
new file mode 100644
index 00000000..ffc3be54
--- /dev/null
+++ b/http/codegen/testdata/streaming_aliased_array_dsls.go
@@ -0,0 +1,28 @@
+package testdata
+
+import (
+	. "goa.design/goa/v3/dsl"
+)
+
+// StreamingAliasedArrayDSL defines a service with a streaming endpoint that uses
+// an array of aliased types with a custom package path.
+var StreamingAliasedArrayDSL = func() {
+	// Define a type in a custom package
+	var CustomInt = Type("CustomInt", Int, func() {
+		Meta("struct:pkg:path", "github.com/example/custompkg")
+	})
+
+	var PayloadType = Type("PayloadType", func() {
+		Attribute("values", ArrayOf(CustomInt))
+	})
+
+	Service("StreamingAliasedArray", func() {
+		Method("Stream", func() {
+			// Use an array of the custom type as streaming payload
+			StreamingPayload(PayloadType)
+			HTTP(func() {
+				GET("/stream")
+			})
+		})
+	})
+}