Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions expr/http_body_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions http/codegen/client_body_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions http/codegen/testdata/streaming_aliased_array_dsls.go
Original file line number Diff line number Diff line change
@@ -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")
})
})
})
}
Loading