mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
Autogenerated API docs
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.2" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.2.3" />
|
||||
<PackageReference Include="DryIoc.dll" Version="4.8.1" />
|
||||
<PackageReference Include="DryIoc.Microsoft.DependencyInjection" Version="5.1.0" />
|
||||
</ItemGroup>
|
||||
|
@@ -9,6 +9,7 @@ using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using NLog.Extensions.Logging;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Instrumentation;
|
||||
@@ -90,6 +91,63 @@ namespace NzbDrone.Host
|
||||
})
|
||||
.AddControllersAsServices();
|
||||
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo
|
||||
{
|
||||
Version = "1.0.0",
|
||||
Title = "Prowlarr",
|
||||
Description = "Prowlarr API docs",
|
||||
License = new OpenApiLicense
|
||||
{
|
||||
Name = "GPL-3.0",
|
||||
Url = new Uri("https://github.com/Prowlarr/Prowlarr/blob/develop/LICENSE")
|
||||
}
|
||||
});
|
||||
|
||||
var apiKeyHeader = new OpenApiSecurityScheme
|
||||
{
|
||||
Name = "X-Api-Key",
|
||||
Type = SecuritySchemeType.ApiKey,
|
||||
Scheme = "apiKey",
|
||||
Description = "Apikey passed as header",
|
||||
In = ParameterLocation.Header,
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "X-Api-Key"
|
||||
},
|
||||
};
|
||||
|
||||
c.AddSecurityDefinition("X-Api-Key", apiKeyHeader);
|
||||
|
||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{ apiKeyHeader, new string[] { } }
|
||||
});
|
||||
|
||||
var apikeyQuery = new OpenApiSecurityScheme
|
||||
{
|
||||
Name = "apikey",
|
||||
Type = SecuritySchemeType.ApiKey,
|
||||
Scheme = "apiKey",
|
||||
Description = "Apikey passed as header",
|
||||
In = ParameterLocation.Query,
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "apikey"
|
||||
},
|
||||
};
|
||||
|
||||
c.AddSecurityDefinition("apikey", apikeyQuery);
|
||||
|
||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{ apikeyQuery, new string[] { } }
|
||||
});
|
||||
});
|
||||
|
||||
services
|
||||
.AddSignalR()
|
||||
.AddJsonProtocol(options =>
|
||||
@@ -181,6 +239,20 @@ namespace NzbDrone.Host
|
||||
|
||||
app.UseWebSockets();
|
||||
|
||||
// Enable middleware to serve generated Swagger as a JSON endpoint.
|
||||
if (BuildInfo.IsDebug)
|
||||
{
|
||||
app.UseSwagger(c =>
|
||||
{
|
||||
c.PreSerializeFilters.Add((swagger, httpReq) =>
|
||||
{
|
||||
swagger.Servers = new List<OpenApiServer> { new OpenApiServer { Url = $"{httpReq.Scheme}://{httpReq.Host.Value}" } };
|
||||
});
|
||||
|
||||
c.RouteTemplate = "docs/{documentName}/openapi.json";
|
||||
});
|
||||
}
|
||||
|
||||
app.UseEndpoints(x =>
|
||||
{
|
||||
x.MapHub<MessageHub>("/signalr/messages").RequireAuthorization("SignalR");
|
||||
|
@@ -20,6 +20,7 @@ namespace Prowlarr.Api.V1.Profiles.App
|
||||
}
|
||||
|
||||
[RestPostById]
|
||||
[Produces("application/json")]
|
||||
public ActionResult<AppProfileResource> Create(AppProfileResource resource)
|
||||
{
|
||||
var model = resource.ToModel();
|
||||
@@ -28,12 +29,14 @@ namespace Prowlarr.Api.V1.Profiles.App
|
||||
}
|
||||
|
||||
[RestDeleteById]
|
||||
[Produces("application/json")]
|
||||
public void DeleteProfile(int id)
|
||||
{
|
||||
_profileService.Delete(id);
|
||||
}
|
||||
|
||||
[RestPutById]
|
||||
[Produces("application/json")]
|
||||
public ActionResult<AppProfileResource> Update(AppProfileResource resource)
|
||||
{
|
||||
var model = resource.ToModel();
|
||||
@@ -43,12 +46,17 @@ namespace Prowlarr.Api.V1.Profiles.App
|
||||
return Accepted(model.Id);
|
||||
}
|
||||
|
||||
[Produces("application/json")]
|
||||
[ProducesResponseType(typeof(AppProfileResource), 200)]
|
||||
[ProducesResponseType(typeof(IDictionary<string, string>), 404)]
|
||||
[ProducesResponseType(500)]
|
||||
public override AppProfileResource GetResourceById(int id)
|
||||
{
|
||||
return _profileService.Get(id).ToResource();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Produces("application/json")]
|
||||
public List<AppProfileResource> GetAll()
|
||||
{
|
||||
return _profileService.All().ToResource();
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user