update subscriptions to add swagger docs

This commit is contained in:
Kukks
2024-06-20 11:52:17 +02:00
parent 6e72a5444f
commit 722d3f7be0
4 changed files with 275 additions and 1 deletions

View File

@@ -1,10 +1,16 @@
using System.IO;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Abstractions.Extensions;
using BTCPayServer.Abstractions.Models;
using BTCPayServer.Abstractions.Services;
using BTCPayServer.HostedServices.Webhooks;
using BTCPayServer.Services;
using BTCPayServer.Services.Apps;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Plugins.Subscriptions
{
@@ -17,6 +23,8 @@ namespace BTCPayServer.Plugins.Subscriptions
public override void Execute(IServiceCollection applicationBuilder)
{
applicationBuilder.AddSingleton<ISwaggerProvider, SubscriptionsSwaggerProvider>();
applicationBuilder.AddSingleton<SubscriptionService>();
applicationBuilder.AddSingleton<IWebhookProvider>(o => o.GetRequiredService<SubscriptionService>());
applicationBuilder.AddHostedService(s => s.GetRequiredService<SubscriptionService>());
@@ -26,4 +34,23 @@ namespace BTCPayServer.Plugins.Subscriptions
base.Execute(applicationBuilder);
}
}
public class SubscriptionsSwaggerProvider: ISwaggerProvider
{
private readonly IFileProvider _fileProvider;
public SubscriptionsSwaggerProvider(IWebHostEnvironment webHostEnvironment)
{
_fileProvider = webHostEnvironment.WebRootFileProvider;
}
public async Task<JObject> Fetch()
{
var file = _fileProvider.GetFileInfo("Resources/swagger.subscriptions.json");
using var reader = new StreamReader(file.CreateReadStream());
return JObject.Parse(await reader.ReadToEndAsync());
}
}
}