Add project files.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Elsa.Features.Services;
|
||||
using FastEndpoints.Swagger;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
namespace Elsa.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extensions to enable the generation of Swagger API Documentation and associated Swagger UI.
|
||||
/// </summary>
|
||||
public static class SwaggerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers Swagger document generator.
|
||||
/// </summary>
|
||||
public static IModule AddSwagger(this IModule module)
|
||||
{
|
||||
Version ver = new(3, 0);
|
||||
|
||||
// Swagger API documentation
|
||||
module.Services.SwaggerDocument(o =>
|
||||
{
|
||||
o.EnableJWTBearerAuth = true;
|
||||
o.DocumentSettings = s =>
|
||||
{
|
||||
s.DocumentName = $"v{ver.Major}";
|
||||
s.Title = "Elsa API";
|
||||
s.Version = $"v{ver.Major}.{ver.Minor}";
|
||||
s.AddAuth("ApiKey", new()
|
||||
{
|
||||
Name = "Authorization",
|
||||
In = NSwag.OpenApiSecurityApiKeyLocation.Header,
|
||||
Type = NSwag.OpenApiSecuritySchemeType.ApiKey,
|
||||
Description = "Enter: ApiKey [your API key]"
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds middleware to enable the Swagger UI at '/swagger'
|
||||
/// </summary>
|
||||
public static IApplicationBuilder UseSwaggerUI(this IApplicationBuilder app)
|
||||
{
|
||||
return app.UseSwaggerGen();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user