With Swashbuckle in particular, (NSwag has it's own means of registering authorization flows) it's not enough to just define the security definition, you also need to register which operations that use it.
Since you want to append the api-key to all operations, your use case is pretty straight forward: simply register the security requirement for your definition, which you can do so like this:
c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>> { { "api key", new[] {} } };
You can read more on how to define, customize, and register different authorization schemes for your operations here.
And for the upcoming v5 of Swashbuckle, the following code could be used:
c.AddSecurityDefinition("api key", new OpenApiSecurityScheme {
Type = SecuritySchemeType.ApiKey,
In = ParameterLocation.Query,
Name = "authorization",
Description = "Authorization query string expects API key"
});
var key = new OpenApiSecurityScheme() { Name = "api key"};
var requirement = new OpenApiSecurityRequirement {
{ key, new List<string>() }
};
c.AddSecurityRequirement(requirement);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…