Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove bases from attributes once they are finalized. #3608

Merged
merged 1 commit into from
Nov 9, 2024
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: 6 additions & 0 deletions expr/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ func (a *AttributeExpr) Finalize() {
}
a.Merge(ru.Attribute())
}

// Now that we've merged the bases, we can clear them. This
// avoids issues where the bases are dupped and modifications
// made to the originals are not reflected in the dups.
a.Bases = nil

for _, nat := range *AsObject(a.Type) {
if pkgPath != "" {
if u := AsUnion(nat.Attribute.Type); u != nil {
Expand Down
1 change: 1 addition & 0 deletions http/codegen/server_decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func TestDecode(t *testing.T) {
{"decode-body-map-string-validate", testdata.PayloadBodyMapStringValidateDSL, testdata.PayloadBodyMapStringValidateDecodeCode},
{"decode-body-map-user", testdata.PayloadBodyMapUserDSL, testdata.PayloadBodyMapUserDecodeCode},
{"decode-body-map-user-validate", testdata.PayloadBodyMapUserValidateDSL, testdata.PayloadBodyMapUserValidateDecodeCode},
{"decode-deep-user", testdata.PayloadDeepUserDSL, testdata.PayloadDeepUserDecodeCode},

{"decode-body-primitive-string-validate", testdata.PayloadBodyPrimitiveStringValidateDSL, testdata.PayloadBodyPrimitiveStringValidateDecodeCode},
{"decode-body-primitive-bool-validate", testdata.PayloadBodyPrimitiveBoolValidateDSL, testdata.PayloadBodyPrimitiveBoolValidateDecodeCode},
Expand Down
16 changes: 16 additions & 0 deletions http/codegen/testdata/payload_decode_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4338,6 +4338,22 @@ func DecodeMethodBodyMapUserValidateRequest(mux goahttp.Muxer, decoder func(*htt
}
`

var PayloadDeepUserDecodeCode = `// marshalServicedeepuserviewsImmediatechildextenderViewToImmediatechildextenderResponseBody
// builds a value of type *ImmediatechildextenderResponseBody from a value of
// type *servicedeepuserviews.ImmediatechildextenderView.
func marshalServicedeepuserviewsImmediatechildextenderViewToImmediatechildextenderResponseBody(v *servicedeepuserviews.ImmediatechildextenderView) *ImmediatechildextenderResponseBody {
if v == nil {
return nil
}
res := &ImmediatechildextenderResponseBody{}
if v.DeepChild != nil {
res.DeepChild = marshalServicedeepuserviewsDeepchildViewToDeepchildResponseBody(v.DeepChild)
}

return res
}
`

var PayloadBodyPrimitiveStringValidateDecodeCode = `// DecodeMethodBodyPrimitiveStringValidateRequest returns a decoder for
// requests sent to the ServiceBodyPrimitiveStringValidate
// MethodBodyPrimitiveStringValidate endpoint.
Expand Down
34 changes: 34 additions & 0 deletions http/codegen/testdata/payload_dsls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,40 @@ var PayloadBodyMapUserValidateDSL = func() {
})
}

var PayloadDeepUserDSL = func() {
var DeepChild = ResultType("DeepChild", func() {
Attribute("name", String)
})
var ImmediateChild = ResultType("ImmediateChild", func() {
Attributes(func() {
Attribute("deep_child", DeepChild)
})
View("other", func() {
Attribute("deep_child")
})
})
var ImmediateChildExtender = ResultType("ImmediateChildExtender", func() {
Extend(ImmediateChild)
Attributes(func() {
Attribute("deep_child", DeepChild)
})
View("other", func() {
Attribute("deep_child")
})
})
var TopLevel = ResultType("TopLevel", func() {
Attributes(func() {
Attribute("immediate_child", ImmediateChildExtender)
})
})
Service("ServiceDeepUser", func() {
Method("MethodDeepUser", func() {
Result(TopLevel)
HTTP(func() { GET("/") })
})
})
}

var PayloadBodyPrimitiveStringValidateDSL = func() {
Service("ServiceBodyPrimitiveStringValidate", func() {
Method("MethodBodyPrimitiveStringValidate", func() {
Expand Down
Loading