Add Authentication to openapi generation.

This commit is contained in:
crobibero 2020-06-01 11:12:33 -06:00
parent 297ab2e423
commit dfe873fc29

View File

@ -99,6 +99,25 @@ namespace Jellyfin.Server.Extensions
return serviceCollection.AddSwaggerGen(c =>
{
c.SwaggerDoc("api-docs", new OpenApiInfo { Title = "Jellyfin API" });
c.AddSecurityDefinition(AuthenticationSchemes.CustomAuthentication, new OpenApiSecurityScheme
{
Type = SecuritySchemeType.ApiKey,
In = ParameterLocation.Header,
Name = "X-Emby-Token",
Description = "API key header parameter"
});
var securitySchemeRef = new OpenApiSecurityScheme
{
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = AuthenticationSchemes.CustomAuthentication },
};
// TODO: Apply this with an operation filter instead of globally
// https://github.com/domaindrivendev/Swashbuckle.AspNetCore#add-security-definitions-and-requirements
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{ securitySchemeRef, Array.Empty<string>() }
});
// Add all xml doc files to swagger generator.
var xmlFiles = Directory.GetFiles(