Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying common headers to multiple responses (doc's issue) #480

Open
outofthisworld opened this issue Jun 14, 2024 · 0 comments
Open

Applying common headers to multiple responses (doc's issue) #480

outofthisworld opened this issue Jun 14, 2024 · 0 comments

Comments

@outofthisworld
Copy link

outofthisworld commented Jun 14, 2024

So i'm trying to get my head around how I can utilise common headers in all my responses. I tried the following

type CommonHeaders struct {
	MyHeader string `header:"X-My-Header"`
}

type OutputSchema struct {
	Body           *OutputBody
	*CommonHeaders `json:"-,omitempty" hidden:"true"`
}

This outputs the following in the docs:

Headers
---------------
CommonHeaders object
       MyHeader   string    required

My-Header string

As you can see the embedded pointer struct gets documented, as well as the header seperately. Even when hidden is true, and json is "-".

I can define the headers in my schema definition instead so that they could be reused across endpoints.. but I still need to be able to write the headers to the response anyway (which I need a struct for)? and since huma.register takes a context.Context rather than the huma.Context I'm struggling to see any way to write headers and have them documented correctly other than to duplicate the headers everywhere?

EDIT:
Have determined it works as expected IF the struct is embedded directly, instead of a pointer.

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

No branches or pull requests

1 participant