Files
NTBug/backend/src/Helpdesk.Api/Infrastructure/SwaggerSetup.cs
T

40 lines
1.4 KiB
C#
Raw Normal View History

using Microsoft.OpenApi;
namespace Helpdesk.Api.Infrastructure;
public static class SwaggerSetup
{
private const string SchemeId = "Bearer";
/// <summary>Swagger UI na <c>/swagger</c> včetně přihlášení access tokenem (NFR-04).</summary>
public static IServiceCollection AddHelpdeskSwagger(this IServiceCollection services)
{
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Univerzitní helpdesk – API",
Version = "v1",
Description = "REST API pro webovou a mobilní aplikaci. Access token získáte přes POST /api/auth/login.",
});
options.AddSecurityDefinition(SchemeId, new OpenApiSecurityScheme
{
Type = SecuritySchemeType.Http,
Scheme = "bearer",
BearerFormat = "JWT",
Description = "Vložte access token (bez předpony „Bearer“).",
});
options.AddSecurityRequirement(document => new OpenApiSecurityRequirement
{
[new OpenApiSecuritySchemeReference(SchemeId, document)] = [],
});
var xml = Path.Combine(AppContext.BaseDirectory, "Helpdesk.Api.xml");
if (File.Exists(xml))
options.IncludeXmlComments(xml);
});
return services;
}
}