Skip to content

Fixed http client code generator#3879

Merged
raphael merged 2 commits intogoadesign:v3from
abocim:ab-fix_codegen
Feb 4, 2026
Merged

Fixed http client code generator#3879
raphael merged 2 commits intogoadesign:v3from
abocim:ab-fix_codegen

Conversation

@abocim
Copy link
Contributor

@abocim abocim commented Jan 30, 2026

This PR fixes a bug we have hit within http client code generator.

In case two or more Methods using Payload(ArrayOf(...)) are defined, generator generates HTTP request body builder function for the first of defined Method only (client/types.go file).

Bug can be reproduced using new added unit test.

Goa design code:

       var PayloadA = Type("PayloadA", func() {
               Attribute("a", String, func() {
                       Pattern("patterna")
               })
       })
       var PayloadB = Type("PayloadB", func() {
               Attribute("a", String, func() {
                       Pattern("patterna")
               })  
               Attribute("b", String, func() {
                       Pattern("patternb")
               })  
               Required("a", "b")
       })  
       Service("ServiceMultipleMethods", func() {
               Method("MethodA", func() {
                       Payload(ArrayOf(PayloadA))
                       HTTP(func() {
                               POST("/")
                       })
               })
               Method("MethodB", func() {
                       Payload(ArrayOf(PayloadB))
                       HTTP(func() {
                               PUT("/")
                       })
               })
       })

Bug is located in http/codegen/client_types.go: func clientType:
In this function there is incorrectly used data.Name attribute for already seen payload types. Attribute is always set to "array" value regardless of real payload type.

Fix:
Using of data.Ref attribute instead, the problem is solved. Since its value corresponds to the real type of Payload "[]*PayloadARequestBody" resp. "[]*PayloadBRequestBody". The code for the both func NewPayloadARequestBody() and func NewPayloadBRequestBody() is properly generated.

@raphael
Copy link
Member

raphael commented Feb 1, 2026

Nice catch! thanks for the nice PR.

@raphael raphael enabled auto-merge (squash) February 1, 2026 01:26
When two or more Methods using `Payload(ArrayOf(...))` are defined,
"HTTP request body builder" function is generated only for the first of defined Method.

Signed-off-by: Adam Bocim <adam.bocim@seznam.cz>
auto-merge was automatically disabled February 1, 2026 07:58

Head branch was pushed to by a user without write access

@abocim
Copy link
Contributor Author

abocim commented Feb 1, 2026

I'm sorry for failed checks before. I updated the source a little.
Now, the both unit tests and integreation tests are passing ok.

@raphael
Copy link
Member

raphael commented Feb 4, 2026

No worries, thanks for the fix!

@raphael raphael merged commit 83a4b9f into goadesign:v3 Feb 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants