goadesign / goa

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

Map as Query Param not working? #3461

Closed pablomadoery closed 7 months ago

pablomadoery commented 7 months ago

Hello,

I am using Goa v3 and trying to have a MapOf(String, Float64) as a query param of a GET endpoint.

Swagger let me put a single string. I tried with different formats like {'1': 100}, but I had no sucess in the decoding stage.

Also, I tried sending a request with Python, with a similar format for that field, with no sucess.

raphael commented 7 months ago

Assuming the following design:

package design

import . "goa.design/goa/v3/dsl"

var _ = Service("svc", func() {
    Method("usemap", func() {
        Payload(func() {
            Attribute("map", MapOf(String, Float64))
        })
        HTTP(func() {
            GET("/usemap")
            Param("map")
        })
    })
})

The generated code will populate the map attribute of the payload with requests using the following query string:

http localhost/usemap?map[foo]=42&map[bar]=43

In this example the payload will be initialized with two keys foo and bar holding the value 42 and 43 respectively.

Alternatively the map itself can be used as the entire payload:

Payload(MapOf(String, Float64))

In which case all query string parameters must have float values.

pablomadoery commented 7 months ago

Thank you very much for the help!