goadesign / goa

🌟 Goa: Elevate Go API development! 🚀 Streamlined design, automatic code generation, and seamless HTTP/gRPC support. ✨
https://goa.design
MIT License
5.54k stars 556 forks source link

Fix handling of custom gen packages #3508

Closed raphael closed 3 months ago

raphael commented 3 months ago

With user defined type protobuf names.

Example of problematic desgin:

    var CustomType = Type("CustomType", func() {
        Meta("struct:name:proto", "CustomType")
        Meta("struct:pkg:path", "types")
        Field(1, "a", Int)
        Field(2, "b", String)
    })
    Service("CustomMessageName", func() {
        Method("Unary", func() {
            Payload(CustomType)
            Result(CustomType)
            GRPC(func() {})
        })
        Method("Stream", func() {
            Payload(CustomType)
            Result(CustomType)
            GRPC(func() {})
        })
    })

Goa would generate function signature that would use the wrong package for the type constructors and results, e.g.:

func NewPayload(message *types.MethodPayload) *types.CustomType {

instead of:

func NewMethodPayload(message *service_payloadpb.MethodPayload) *types.CustomType {

The problem is the blind merge of all the payload metadata including the key that defines the custom package path.