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

How to specify the header name in a Parameters or Response definition? #1135

Closed
flimzy opened this issue Aug 15, 2017 · 3 comments
Closed

How to specify the header name in a Parameters or Response definition? #1135

flimzy opened this issue Aug 15, 2017 · 3 comments
Labels
generate spec Related to spec generation from code

Comments

@flimzy
Copy link
Contributor

flimzy commented Aug 15, 2017

Problem statement

What is the proper way to set the header name in a param or response definition? Example:

type FooResponse struct {
// X-Foo header
//
// in: header
// name: X-Foo
XFoo string
// ... 
}

This creates a "valid" swagger definition, as:

  "headers": {
    "XFoo": {
      "type": "string",
      "description": "X-Foo header\n\nin: header\nname: X-Foo"
    },

Is this the best I can do? Or is there some way to instead get:

  "headers": {
    "X-Foo": {
      "type": "string",
      "description": "X-Foo header"
    },

?

@casualjim
Copy link
Member

I believe you can use a json:"X-Foo" tag to allow for overriding the name

@flimzy
Copy link
Contributor Author

flimzy commented Aug 15, 2017

Brilliant! That does indeed do the trick. Thanks!

@flimzy flimzy closed this as completed Aug 15, 2017
@knollfear
Copy link

For anyone that got here via a google search the answer is

type FooResponse struct {
// X-Foo header
XFoo string json:"X-Foo"
// ...
}

or at least that is what worked for me.

@fredbi fredbi added the generate spec Related to spec generation from code label Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generate spec Related to spec generation from code
Projects
None yet
Development

No branches or pull requests

4 participants