UseSwaggerUi3 : SwaggerSecuritySchemeType.ApiKey in Header ignored
See original GitHub issueHello! In order to transmit header value to all my APIs, I used settings.GeneratorSettings.DocumentProcessors.Add(new SecurityDefinitionAppender with app.UseSwaggerUi.
app.UseSwaggerUi(typeof(Startup).GetTypeInfo().Assembly, settings =>
{
settings.GeneratorSettings.DocumentProcessors.Add(new SecurityDefinitionAppender("TEST_HEADER", new SwaggerSecurityScheme
{
Type = SwaggerSecuritySchemeType.ApiKey,
Name = "TEST_HEADER",
In = SwaggerSecurityApiKeyLocation.Header,
Description = "TEST_HEADER"
}));
});
In that way, all works like a charm !
curl -X GET --header 'Accept: text/html' --header 'TEST_HEADER: testvalue' 'http://localhost:60047/api/v2/users'
actionContext.HttpContext.Request.Headers["TEST_HEADER"] = "testvalue"
Then I try to update to UseSwaggerUi3 (because it’s better)
app.UseSwaggerUi3(typeof(Startup).GetTypeInfo().Assembly, settings =>
{
settings.GeneratorSettings.DocumentProcessors.Add(new SecurityDefinitionAppender("TEST_HEADER", new SwaggerSecurityScheme
{
Type = SwaggerSecuritySchemeType.ApiKey,
Name = "TEST_HEADER",
In = SwaggerSecurityApiKeyLocation.Header,
Description = "TEST_HEADER"
}));
});
But now, the header is not sent 😦
curl -X GET "http://localhost:60047/api/v2/users" -H "accept: application/json"
actionContext.HttpContext.Request.Headers["TEST_HEADER"] = {}
I use : NSwag.AspNetCore Version=11.17.2
Thank you in advance, and if you have another method to send headers globally it could be great 😃
Rémi
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (5 by maintainers)
I’ve just setup like that and it works fine:
Hi,
According to the description, seems that the issue is only when trying to send the header with the token, I faced something similar, and the issue was that I didn’t include the OperationProcessor in the GeneratorSettings.
In Short, adding this line would help you:
Hope it helps.
Cheers!