0

If my method in my API looks for some custom property that is in the header, ie HttpContext.Current.Request.Headers.Exists("foobar"), is there a way for me to decorate that method so that Swashbuckle can generate that header for Swagger to test the method with?

I've had good success with decorating with SwaggerResponse for my methods, to specify return types/codes, but not specifying headers.

I've also been able to add HTTP headers to EVERY request by the way of injecting custom JavaScript:

(function () {
    $(function () {
        $('#input_apiKey').off();
        $('#input_apiKey').on('change', function () {
            var key = this.value;
            if (key && key.trim() !== '') {
                swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("Authorization", key, "header"));
            }
        });
    });
})();

and in SwaggerConfig.cs:

c.InjectJavaScript(thisAssembly, "Api.CustomContent.jwt-auth.js");
hkf
  • 4,440
  • 1
  • 30
  • 44
  • Have a look at this: http://stackoverflow.com/questions/20618900/webapi-mapping-parameter-to-header-value It probably answers your question. – venerik Jun 01 '16 at 14:33
  • @venerik It almost does, I'll write a solution and answer it myself in a bit. – hkf Jun 02 '16 at 22:40

0 Answers0