Files
duplicati/Duplicati/WebserverCore/Extensions/WebApplicationExtensions.cs
T
Kenneth Skovhede 7e77217171 Fix Swagger exposed API.
Changed order or Json serializers to fix the parsing issue for enums.
Removed support code for controllers as we are only using minimal API.
2024-09-06 10:50:06 +02:00

34 lines
1.1 KiB
C#

using System.Reflection;
using Duplicati.WebserverCore.Abstractions;
using Duplicati.WebserverCore.Middlewares;
namespace Duplicati.WebserverCore.Extensions;
public static class WebApplicationExtensions
{
public static WebApplication AddEndpoints(this WebApplication application)
{
return AddV1(application);
}
private static WebApplication AddV1(WebApplication application)
{
var mapperInterfaceType = typeof(IEndpointV1);
var endpoints =
typeof(WebApplicationExtensions).Assembly.DefinedTypes
.Where(t => t.ImplementedInterfaces.Contains(mapperInterfaceType))
.ToArray();
var group = application.MapGroup("/api/v1")
.AddEndpointFilter<LanguageFilter>()
.AddEndpointFilter<HostnameFilter>();
foreach (var endpoint in endpoints)
{
var methodMap = endpoint.GetMethod(nameof(IEndpointV1.Map), BindingFlags.Static | BindingFlags.Public);
methodMap!.Invoke(null, [group]);
}
return application;
}
}