Swagger: Creating the swagger page

This commit is contained in:
Zoe Roux 2021-09-15 21:54:50 +02:00
parent 09ff2e795d
commit ba37a7cb9b
7 changed files with 68 additions and 6 deletions

View File

@ -283,7 +283,7 @@ namespace Kyoo.Core
builder.ReadFrom.Services(services);
const string template =
"[{@t:HH:mm:ss} {@l:u3} {Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1), 15} "
"[{@t:HH:mm:ss} {@l:u3} {Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1), 25} "
+ "({@i:D10})] {@m}{#if not EndsWith(@m, '\n')}\n{#end}{@x}";
if (SystemdHelpers.IsSystemdService())

View File

@ -27,6 +27,8 @@ using Microsoft.Extensions.Options;
// We use threads so tasks are not always awaited.
#pragma warning disable 4014
// Private items that are external can't start with an _
#pragma warning disable IDE1006
namespace Kyoo.Core.Controllers
{

View File

@ -38,6 +38,7 @@
<ProjectReference Include="../Kyoo.SqLite/Kyoo.SqLite.csproj" />
<ProjectReference Include="../Kyoo.Authentication/Kyoo.Authentication.csproj" />
<ProjectReference Include="../Kyoo.WebApp/Kyoo.WebApp.csproj" />
<ProjectReference Include="../Kyoo.Swagger/Kyoo.Swagger.csproj" />
</ItemGroup>
<Target Name="BuildTranscoder" BeforeTargets="BeforeBuild" Condition="'$(SkipTranscoder)' != 'true' And !Exists('$(TranscoderRoot)/build/$(TranscoderBinary)')">

View File

@ -28,6 +28,7 @@ using Kyoo.Core.Models.Options;
using Kyoo.Core.Tasks;
using Kyoo.Postgresql;
using Kyoo.SqLite;
using Kyoo.Swagger;
using Kyoo.TheMovieDb;
using Kyoo.TheTvdb;
using Kyoo.Utils;
@ -75,7 +76,8 @@ namespace Kyoo.Core
typeof(PostgresModule),
typeof(SqLiteModule),
typeof(PluginTvdb),
typeof(PluginTmdb)
typeof(PluginTmdb),
typeof(SwaggerModule)
);
}

View File

@ -208,6 +208,7 @@ namespace Kyoo.Core.Api
return Ok();
}
[HttpDelete]
[PartialPermission(Kind.Delete)]
public virtual async Task<IActionResult> Delete(Dictionary<string, string> where)
{

View File

@ -16,12 +16,68 @@
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.IO;
using Kyoo.Abstractions.Controllers;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
namespace Kyoo.Swagger
{
/// <summary>
/// A module to enable a swagger interface and an OpenAPI endpoint to document Kyoo.
/// </summary>
public class SwaggerModule
public class SwaggerModule : IPlugin
{
/// <inheritdoc />
public string Slug => "swagger";
/// <inheritdoc />
public string Name => "Swagger";
/// <inheritdoc />
public string Description => "A swagger interface and an OpenAPI endpoint to document Kyoo.";
/// <inheritdoc />
public Dictionary<string, Type> Configuration => new();
/// <inheritdoc />
public void Configure(IServiceCollection services)
{
services.AddSwaggerGen(x =>
{
x.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1",
Title = "Kyoo API",
Description = "The Kyoo's public API",
Contact = new OpenApiContact
{
Name = "Kyoo's github",
Url = new Uri("https://github.com/AnonymusRaccoon/Kyoo/issues/new/choose")
},
License = new OpenApiLicense
{
Name = "GPL-3.0-or-later",
Url = new Uri("https://github.com/AnonymusRaccoon/Kyoo/blob/master/LICENSE")
}
});
foreach (string documentation in Directory.GetFiles(AppContext.BaseDirectory, "*.xml"))
x.IncludeXmlComments(documentation);
});
}
/// <inheritdoc />
public IEnumerable<IStartupAction> ConfigureSteps => new IStartupAction[]
{
SA.New<IApplicationBuilder>(app => app.UseSwagger(), SA.Before + 1),
SA.New<IApplicationBuilder>(app => app.UseSwaggerUI(x =>
{
x.SwaggerEndpoint("/swagger/v1/swagger.json", "Kyoo v1");
}), SA.Before)
};
}
}