mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
cut out swagger for now, not working and hacky, will redo
This commit is contained in:
parent
ef2ebd776f
commit
11c7c64b1a
5 changed files with 3 additions and 66 deletions
|
|
@ -1,13 +1,9 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.ApplicationInsights.Extensibility.Implementation;
|
||||
using Microsoft.ApplicationInsights.Extensibility.Implementation;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Newtonsoft.Json;
|
||||
using Swashbuckle.AspNetCore.Swagger;
|
||||
|
||||
namespace FilterLists.Api.DependencyInjection.Extensions
|
||||
{
|
||||
|
|
@ -21,7 +17,6 @@ public static void AddFilterListsApi(this IServiceCollection services)
|
|||
services.AddMvcCustom();
|
||||
services.AddRoutingCustom();
|
||||
services.AddApiVersioning();
|
||||
services.AddSwaggerGenCustom();
|
||||
TelemetryDebugWriter.IsTracingDisabled = true;
|
||||
}
|
||||
|
||||
|
|
@ -43,35 +38,5 @@ private static void AddMvcCustom(this IServiceCollection services) =>
|
|||
|
||||
private static void AddRoutingCustom(this IServiceCollection services) =>
|
||||
services.AddRouting(opts => opts.LowercaseUrls = true);
|
||||
|
||||
private static void AddSwaggerGenCustom(this IServiceCollection services) =>
|
||||
services.AddSwaggerGen(opts =>
|
||||
{
|
||||
opts.SwaggerDoc("v1",
|
||||
new Info
|
||||
{
|
||||
Title = "FilterLists API",
|
||||
Version = "v1",
|
||||
Description =
|
||||
"An API for FilterLists, the independent, comprehensive directory of all public filter and hosts lists for advertisements, trackers, malware, and annoyances." +
|
||||
Environment.NewLine +
|
||||
"Home: https://filterlists.com" +
|
||||
Environment.NewLine +
|
||||
"Data Model Docs: https://github.com/collinbarrett/FilterLists/wiki/Data-Model_sidebar",
|
||||
Contact =
|
||||
new Contact
|
||||
{
|
||||
Url = "https://github.com/collinbarrett/FilterLists/",
|
||||
Name = "FilterLists - GitHub"
|
||||
},
|
||||
License = new License
|
||||
{
|
||||
Name = "MIT License",
|
||||
Url = "https://github.com/collinbarrett/FilterLists/blob/master/LICENSE"
|
||||
}
|
||||
});
|
||||
opts.IncludeXmlComments(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath,
|
||||
"FilterLists.Api.xml"));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +35,6 @@
|
|||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.2" />
|
||||
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.2.12-alpha" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.8" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Swashbuckle.AspNetCore.Swagger;
|
||||
|
||||
namespace FilterLists.Api
|
||||
{
|
||||
|
|
@ -47,31 +46,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
|||
app.UseStaticFiles();
|
||||
app.UseCookiePolicy();
|
||||
app.UseMvc();
|
||||
app.UseSwagger(opts =>
|
||||
{
|
||||
opts.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Host = httpReq.Host.Value);
|
||||
//TODO: remove preprocessor directives
|
||||
#if RELEASE
|
||||
opts.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.BasePath = "/api");
|
||||
#endif
|
||||
opts.RouteTemplate = "docs/{documentName}/swagger.json";
|
||||
UseLowercaseControllerNameInSwaggerHack(opts);
|
||||
});
|
||||
app.UseSwaggerUI(opts =>
|
||||
{
|
||||
opts.SwaggerEndpoint("v1/swagger.json", "FilterLists API v1");
|
||||
opts.DocumentTitle = "FilterLists API v1";
|
||||
opts.RoutePrefix = "docs";
|
||||
});
|
||||
}
|
||||
|
||||
//TODO: remove hack (https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/74#issuecomment-386762178)
|
||||
private static void UseLowercaseControllerNameInSwaggerHack(SwaggerOptions opts) =>
|
||||
opts.PreSerializeFilters.Add((document, request) =>
|
||||
{
|
||||
var paths = document.Paths.ToDictionary(item => item.Key.ToLowerInvariant(), item => item.Value);
|
||||
document.Paths.Clear();
|
||||
foreach (var pathItem in paths) document.Paths.Add(pathItem.Key, pathItem.Value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,6 @@
|
|||
namespace FilterLists.Api.V1.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
//TODO: use versioning without needing to manually specify in swagger-ui (https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/370)
|
||||
[Route("v{version:apiVersion}/[controller]")]
|
||||
[ResponseCache(Duration = 86400)]
|
||||
public abstract class BaseController : Controller
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ const GitHubLink = () =>
|
|||
</a>;
|
||||
|
||||
const ApiLink = () =>
|
||||
<a href="/api/docs/index.html"
|
||||
title="API Swagger docs">
|
||||
<a href="/api/v1/lists"
|
||||
title="API lists endpoint">
|
||||
API
|
||||
</a>;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue