Skip to content

Commit baf3693

Browse files
authored
bug: fix support for streaming aliased array types with custom package paths (#3712)
1 parent 4fbaa0a commit baf3693

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

expr/http_body_types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,14 @@ func httpStreamingBody(e *HTTPEndpointExpr) *AttributeExpr {
227227
return DupAtt(att)
228228
}
229229
const suffix = "StreamingBody"
230+
dupped := DupAtt(att)
231+
RemovePkgPath(dupped)
232+
appendSuffix(dupped.Type, suffix)
230233
ut := &UserTypeExpr{
231-
AttributeExpr: DupAtt(att),
234+
AttributeExpr: dupped,
232235
TypeName: concat(e.Name(), "Streaming", "Body"),
233236
UID: e.Service.Name() + "#" + e.Name() + "StreamingBody",
234237
}
235-
appendSuffix(ut.Attribute().Type, suffix)
236238

237239
return &AttributeExpr{
238240
Type: ut,

http/codegen/client_body_types_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func TestBodyTypeInit(t *testing.T) {
5252
{"result-explicit-body-user-type", testdata.ExplicitBodyUserResultMultipleViewsDSL, 3, ExplicitBodyUserResultMultipleViewsInitCode},
5353
{"result-explicit-body-object", testdata.ExplicitBodyUserResultObjectDSL, 3, ExplicitBodyObjectInitCode},
5454
{"result-explicit-body-object-views", testdata.ExplicitBodyUserResultObjectMultipleViewDSL, 3, ExplicitBodyObjectViewsInitCode},
55+
{"body-streaming-aliased-array", testdata.StreamingAliasedArrayDSL, 4, StreamingAliasedArrayBodyInitCode},
5556
}
5657
for _, c := range cases {
5758
t.Run(c.Name, func(t *testing.T) {
@@ -279,6 +280,21 @@ func NewMethodExplicitBodyUserResultObjectMultipleViewResulttypemultipleviewsOK(
279280
return v
280281
}
281282
`
283+
284+
const StreamingAliasedArrayBodyInitCode = `// NewStreamStreamingBody builds the HTTP request body from the payload of the
285+
// "Stream" endpoint of the "StreamingAliasedArray" service.
286+
func NewStreamStreamingBody(p *streamingaliasedarray.PayloadType) *StreamStreamingBody {
287+
body := &StreamStreamingBody{}
288+
if p.Values != nil {
289+
body.Values = make([]CustomIntStreamingBody, len(p.Values))
290+
for i, val := range p.Values {
291+
body.Values[i] = CustomIntStreamingBody(val)
292+
}
293+
}
294+
return body
295+
}
296+
`
297+
282298
const MixedPayloadInBodyClientTypesFile = `// MethodARequestBody is the type of the "ServiceMixedPayloadInBody" service
283299
// "MethodA" endpoint HTTP request body.
284300
type MethodARequestBody struct {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package testdata
2+
3+
import (
4+
. "goa.design/goa/v3/dsl"
5+
)
6+
7+
// StreamingAliasedArrayDSL defines a service with a streaming endpoint that uses
8+
// an array of aliased types with a custom package path.
9+
var StreamingAliasedArrayDSL = func() {
10+
// Define a type in a custom package
11+
var CustomInt = Type("CustomInt", Int, func() {
12+
Meta("struct:pkg:path", "github.com/example/custompkg")
13+
})
14+
15+
var PayloadType = Type("PayloadType", func() {
16+
Attribute("values", ArrayOf(CustomInt))
17+
})
18+
19+
Service("StreamingAliasedArray", func() {
20+
Method("Stream", func() {
21+
// Use an array of the custom type as streaming payload
22+
StreamingPayload(PayloadType)
23+
HTTP(func() {
24+
GET("/stream")
25+
})
26+
})
27+
})
28+
}

0 commit comments

Comments
 (0)