Update packages, use explicit type, use Microsoft OpenApi package

This commit is contained in:
2025-06-12 17:43:22 +02:00
parent b3ca1ba703
commit d91b837e44
32 changed files with 138 additions and 230 deletions

View File

@@ -3,8 +3,6 @@ using FluentValidation;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Options;
using Vegasco.WebApi.Authentication;
using Vegasco.WebApi.Endpoints;
using Vegasco.WebApi.Endpoints.OpenApi;
using Vegasco.WebApi.Persistence;
namespace Vegasco.WebApi.Common;
@@ -14,14 +12,12 @@ public static class DependencyInjectionExtensions
/// <summary>
/// Adds all the WebApi related services to the Dependency Injection container.
/// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
/// <param name="environment"></param>
/// <param name="builder"></param>
public static void AddWebApiServices(this IHostApplicationBuilder builder)
{
builder.Services
.AddMiscellaneousServices()
.AddOpenApi()
.AddCustomOpenApi()
.AddApiVersioning()
.AddAuthenticationAndAuthorization(builder.Environment);
@@ -38,7 +34,6 @@ public static class DependencyInjectionExtensions
], ServiceLifetime.Singleton);
services.AddHealthChecks();
services.AddEndpointsFromAssemblyContaining<IWebApiMarker>();
services.AddHttpContextAccessor();
@@ -47,32 +42,30 @@ public static class DependencyInjectionExtensions
return services;
}
private static IServiceCollection AddOpenApi(this IServiceCollection services)
private static IServiceCollection AddCustomOpenApi(this IServiceCollection services)
{
services.ConfigureOptions<ConfigureSwaggerGenOptions>();
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(o =>
services.AddOpenApi(o =>
{
o.CustomSchemaIds(type =>
o.CreateSchemaReferenceId = jsonTypeInfo =>
{
if (string.IsNullOrEmpty(type.FullName))
if (string.IsNullOrEmpty(jsonTypeInfo.Type.FullName))
{
return type.Name;
return jsonTypeInfo.Type.Name;
}
var fullClassName = type.FullName;
string? fullClassName = jsonTypeInfo.Type.FullName;
if (!string.IsNullOrEmpty(type.Namespace))
if (!string.IsNullOrEmpty(jsonTypeInfo.Type.Namespace))
{
fullClassName = fullClassName
.Replace(type.Namespace, "")
.Replace(jsonTypeInfo.Type.Namespace, "")
.TrimStart('.');
}
fullClassName = fullClassName.Replace('+', '_');
return fullClassName;
});
};
});
return services;