huma
huma copied to clipboard
[feature] cannot add headers in error response in openapi doc
Those header key are set by http middleware, so adding to openapi is the job to be done.
You need to update your middleware then. Use factory pattern, For example, for my routing group, I want to ensure everything need to be authed. So, I wrote my coed as follow
items.UseMiddleware(middleware.HumaAuthMiddleware(items))
func HumaAuthMiddleware(g *huma.Group) func(huma.Context, func(huma.Context)) {
routes.UseSecurity(g, routes.BearerScheme)
return wrapHTTPMiddleware(AuthMiddleware)
}
func UseSecurity(g *huma.Group, scheme string) {
g.UseSimpleModifier(func(o *huma.Operation) {
if len(o.Security) == 0 {
o.Security = []map[string][]string{{scheme: {}}}
}
})
}
You can do similar for the response header. Just need to tweak the code. I hope this can help you