refactor: Service Swagger-Erweiterungen entfernen und direkt in Program.cs hinzufügen
This commit is contained in:
@@ -18,6 +18,10 @@ using HRD.WebApi.Helpers;
|
|||||||
using StaffDBServer.SharedControllers;
|
using StaffDBServer.SharedControllers;
|
||||||
using HRD.LDAPService;
|
using HRD.LDAPService;
|
||||||
using Microsoft.AspNetCore.Server.IISIntegration;
|
using Microsoft.AspNetCore.Server.IISIntegration;
|
||||||
|
using NSwag.Generation.Processors.Security;
|
||||||
|
using NSwag;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
|
|
||||||
AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs) =>
|
AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs) =>
|
||||||
{
|
{
|
||||||
@@ -60,7 +64,43 @@ try
|
|||||||
|
|
||||||
builder.Services.AddSingleton<ILoggerManager, LoggerManager>();
|
builder.Services.AddSingleton<ILoggerManager, LoggerManager>();
|
||||||
|
|
||||||
builder.Services.ConfigureSwagger();
|
//SWAGGER
|
||||||
|
builder.Services.AddSwaggerDocument(config =>
|
||||||
|
{
|
||||||
|
#region add Bearer Authorization
|
||||||
|
|
||||||
|
config.AddSecurity("JWT", Enumerable.Empty<string>(), new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Type = OpenApiSecuritySchemeType.ApiKey,
|
||||||
|
Name = "Authorization",
|
||||||
|
In = OpenApiSecurityApiKeyLocation.Header,
|
||||||
|
Description = "Bearer JWT token."
|
||||||
|
});
|
||||||
|
|
||||||
|
config.OperationProcessors.Add(
|
||||||
|
new AspNetCoreOperationSecurityScopeProcessor("JWT"));
|
||||||
|
|
||||||
|
#endregion add Bearer Authorization
|
||||||
|
|
||||||
|
config.PostProcess = document =>
|
||||||
|
{
|
||||||
|
document.Info.Version = "V." + PlatformServices.Default.Application.ApplicationVersion + "; " + PlatformServices.Default.Application.RuntimeFramework;
|
||||||
|
document.Info.Title = $" {PlatformServices.Default.Application.ApplicationName} API";
|
||||||
|
document.Info.Description = $" {PlatformServices.Default.Application.ApplicationName} Backend ";
|
||||||
|
document.Info.TermsOfService = "None";
|
||||||
|
document.Info.Contact = new NSwag.OpenApiContact
|
||||||
|
{
|
||||||
|
Name = "IT",
|
||||||
|
Email = string.Empty,
|
||||||
|
Url = "https://hensel-recycling.com"
|
||||||
|
};
|
||||||
|
document.Info.License = new NSwag.OpenApiLicense
|
||||||
|
{
|
||||||
|
Name = "Commercial License",
|
||||||
|
Url = "https://hensel-recycling.com"
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
builder.Services.ConfigureRepositoryWrapper(); // add repos
|
builder.Services.ConfigureRepositoryWrapper(); // add repos
|
||||||
|
|
||||||
@@ -103,7 +143,7 @@ try
|
|||||||
app.UseOpenApi();
|
app.UseOpenApi();
|
||||||
app.UseDALMiddleware();
|
app.UseDALMiddleware();
|
||||||
app.UseJwtMiddleware();
|
app.UseJwtMiddleware();
|
||||||
app.ConfigureSwagger();
|
app.UseSwaggerUi(cfg => cfg.DocExpansion = "none");
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
|
||||||
using NSwag;
|
|
||||||
using NSwag.Generation.Processors.Security;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace StaffDBServer.SharedExtensions
|
|
||||||
{
|
|
||||||
public static class ServiceSwaggerExtensions
|
|
||||||
{
|
|
||||||
public static void ConfigureSwagger(this IApplicationBuilder app)
|
|
||||||
{
|
|
||||||
app.UseSwaggerUi(cfg =>
|
|
||||||
cfg.DocExpansion = "none" //"list"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ConfigureSwagger(this IServiceCollection services)
|
|
||||||
{
|
|
||||||
services.AddSwaggerDocument(config =>
|
|
||||||
{
|
|
||||||
#region add Bearer Authorization
|
|
||||||
|
|
||||||
config.AddSecurity("JWT", Enumerable.Empty<string>(), new OpenApiSecurityScheme
|
|
||||||
{
|
|
||||||
Type = OpenApiSecuritySchemeType.ApiKey,
|
|
||||||
Name = "Authorization",
|
|
||||||
In = OpenApiSecurityApiKeyLocation.Header,
|
|
||||||
Description = "Bearer JWT token."
|
|
||||||
});
|
|
||||||
|
|
||||||
config.OperationProcessors.Add(
|
|
||||||
new AspNetCoreOperationSecurityScopeProcessor("JWT"));
|
|
||||||
|
|
||||||
#endregion add Bearer Authorization
|
|
||||||
|
|
||||||
config.PostProcess = document =>
|
|
||||||
{
|
|
||||||
document.Info.Version = "V." + PlatformServices.Default.Application.ApplicationVersion + "; " + PlatformServices.Default.Application.RuntimeFramework;
|
|
||||||
document.Info.Title = $" {PlatformServices.Default.Application.ApplicationName} API";
|
|
||||||
document.Info.Description = $" {PlatformServices.Default.Application.ApplicationName} Backend ";
|
|
||||||
document.Info.TermsOfService = "None";
|
|
||||||
document.Info.Contact = new NSwag.OpenApiContact
|
|
||||||
{
|
|
||||||
Name = "IT",
|
|
||||||
Email = string.Empty,
|
|
||||||
Url = "https://hensel-recycling.com"
|
|
||||||
};
|
|
||||||
document.Info.License = new NSwag.OpenApiLicense
|
|
||||||
{
|
|
||||||
Name = "Commercial License",
|
|
||||||
Url = "https://hensel-recycling.com"
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user