Does Swagger 2.0 handle custom headers

3,204 views
Skip to first unread message

Bill Hainaut

unread,
Sep 25, 2014, 7:29:12 AM9/25/14
to swagger-sw...@googlegroups.com
If my API requires all requests to have a custom header:

X-ClientID: "somevalue"

How do I incorporate that into the JSON that describes the API so that the "Try It" button will work?
It was not obvious in looking at the schema here: https://github.com/wordnik/swagger-spec/blob/master/schemas/v2.0/schema.json


Ron

unread,
Sep 25, 2014, 8:51:33 AM9/25/14
to swagger-sw...@googlegroups.com
Hi Bill,

There are two separate things here. The first is if/how you describe it in the schema and the second is if/how you incorporate it into swagger-ui.

There are two ways to define a header parameter in the Swagger specification.
First one is via a header parameter. This means that you'd need to add the header parameter to each of the operations.
Swagger 2.0 allows you to also define a parameter at the path level (affecting all operations on it), and you can also define a parameter in the parameter definitions and refer to it from all places.
The second is via a security definition. You can declare that you have a security header that needs to be sent for an operation. It can be declared globally for all operations or specifically for each operation.
The security section of the Swagger 2.0 will soon be finalized and you could have a look at that.

Now, when it comes to swagger-ui, it depends on how you decide to go with the specification.
If you choose to add a header parameter for each operation, it'll appear as an input parameter in the operation parameter form.
If you choose to add it as a security header, you can use https://github.com/wordnik/swagger-ui#header-parameters to add your parameter. Keep in mind, you can use this method even if you don't add to the Swagger specification.



--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages