mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 09:54:30 +01:00
d5d0be5824
* Editorconfig: Add space_before_self_closing setting This was a difference between the way dotnet-format and Rider format code. See https://www.jetbrains.com/help/rider/EditorConfig_Index.html * Editorconfig: Keep 4 spaces indentation for Swagger JSON files They are all formatted that way, let's keep it like that. * Apply dotnet-format, mostly white-space related changes
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServer.Abstractions.Contracts;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.FileProviders;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace BTCPayServer.Services;
|
|
|
|
public class DefaultSwaggerProvider : ISwaggerProvider
|
|
{
|
|
private readonly IFileProvider _fileProvider;
|
|
|
|
public DefaultSwaggerProvider(IWebHostEnvironment webHostEnvironment, ISettingsAccessor<PoliciesSettings> policies)
|
|
{
|
|
|
|
_fileProvider = webHostEnvironment.WebRootFileProvider;
|
|
Policies = policies;
|
|
}
|
|
|
|
public BTCPayServerEnvironment Env { get; }
|
|
public ISettingsAccessor<PoliciesSettings> Policies { get; }
|
|
|
|
public async Task<JObject> Fetch()
|
|
{
|
|
|
|
JObject json = new JObject();
|
|
var directoryContents = _fileProvider.GetDirectoryContents("swagger/v1");
|
|
foreach (IFileInfo fi in directoryContents)
|
|
{
|
|
await using var stream = fi.CreateReadStream();
|
|
using var reader = new StreamReader(fi.CreateReadStream());
|
|
var jObject = JObject.Parse(await reader.ReadToEndAsync());
|
|
if (jObject.Remove("x_experimental") && !Policies.Settings.Experimental)
|
|
continue;
|
|
json.Merge(jObject);
|
|
}
|
|
|
|
return json;
|
|
}
|
|
}
|