Skip to content

Can't set the Operation's Errors in a group modifier #878

@dresswithpockets

Description

@dresswithpockets

I've got something like this:

	internalApi := huma.NewGroup(api, "/internal")

	requireUserAuthHandler := auth.CreateRequireUserAuthHandler(internalApi)
	internalApi.UseSimpleModifier(func(op *huma.Operation) {
		op.Tags = append(op.Tags, "Internal")
		if _, noAuth := op.Metadata["NoUserAuth"]; !noAuth {
			op.Security = append(op.Security, map[string][]string{"SessionCookie": {}})
			op.Middlewares = append(op.Middlewares, auth.UserAuthHandler, requireUserAuthHandler)
			op.Errors = append(op.Errors, http.StatusUnauthorized)
		}
	})

	sessionApi := huma.NewGroup(internalApi, "/session")
	// a bunch of calls to huma.Register(sessionApi, ...)

When I specify Errors in the Operation passed to huma.Register, it's correctly defined in the OpenAPI document. But, it doesn't reflect the error codes updated by the simple modifier. The changes in the modifier to Middlewares, Security, and Tags are reflected correctly by the OpenAPI document, only changes to Errors are not reflected in the document.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions