How can I add individual headers on different controllers. E.g.:
Controller Name: Controller1, Custom header: Header1
Controller Name: Controller2, Custom header: Header2
The headers should be displayed for all the apis under the specific controller
This can be solved by adding an OperationFilter to your swagger configuration. First you have to provide a class that implements
IOperationFilter
. TheApply
method receives anOperation
parameter which contains the controller name in thetag
field. When the Swagger UI is rendered, theApply
method will be called for each method in the API. You could even provide individual parameters for each API method, asOperation
also contains the operationId.In the debugger, with a controller named
ExampleController
, it looks like this:The result in the Swagger UI is a special parameter that is only applied to the API of my Example controller:
Tell Swagger to use your OperationFilter by adding one line in the
Register
method of theSwaggerConfig
class:The idea to this solution is based on ShaTin's answer: How to send custom headers with requests in Swagger UI?