danielgtaylor / huma

Huma REST/HTTP API Framework for Golang with OpenAPI 3.1
https://huma.rocks/
MIT License
1.87k stars 138 forks source link

Docs UI doesn't handle multiple cookies properly #403

Open erikborsos opened 4 months ago

erikborsos commented 4 months ago

I've noticed an issue (maybe it's a skill issue from my side) with how the docs page displays multiple cookies.

When only a single cookie is set as a result, everything appears fine in the UI. However, when multiple cookies are set, the UI doesn't seem to render it correctly (particularly in nesting).

Set single cookie:

type SingleOutput struct {
    SetCookie *http.Cookie `header:"Set-Cookie"`
}

Result:

image

Set multiple cookies:

type MultipleOutput struct {
    SetCookie []*http.Cookie `header:"Set-Cookie"`
}

Result:

image

I can't fold in the Set-Cookie object, which can be a bit confusing if there is more header information set.

danielgtaylor commented 4 months ago

Nice find, this is a bug as it should be treated as a string.

krisatverbidio commented 2 months ago

@danielgtaylor It looks like in the case of a slice of []*http.Cookie, it is nesting into the cookie object. So it seems if we can stop nesting if it is a []*http.Cookie type, that should resolve this issue.

I'm not familiar enough with the code that does the reflection to generate the schema in Huma right now since I'm fairly new to the project, so I'm not sure of the "best" way to accomplish this. I'm not sure if the right spot is to throw it into _findInType, or if it belongs in a better spot.