mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17:11:10 +00:00
Adds editorconfig and refactors to the established rules
This commit is contained in:
1 parent
712a0f2b27
commit
cd44f11d9e
138 files changed
+1799
-1629
No files matched your search
@@ -36,8 +36,8 @@ public class ConfigureSwaggerOptions : IConfigureNamedOptions<SwaggerGenOptions>
|
||||
public void Configure(SwaggerGenOptions options)
|
||||
{
|
||||
// add swagger document for every API version discovered
|
||||
foreach (var description in _provider.ApiVersionDescriptions)
|
||||
options.SwaggerDoc(description.GroupName,CreateVersionInfo(description));
|
||||
foreach (ApiVersionDescription description in _provider.ApiVersionDescriptions)
|
||||
options.SwaggerDoc(description.GroupName, CreateVersionInfo(description));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,7 +57,7 @@ public class ConfigureSwaggerOptions : IConfigureNamedOptions<SwaggerGenOptions>
|
||||
/// <returns>The created <see cref="OpenApiInfo"/> instance.</returns>
|
||||
private OpenApiInfo CreateVersionInfo(ApiVersionDescription description)
|
||||
{
|
||||
var info = new OpenApiInfo()
|
||||
OpenApiInfo info = new()
|
||||
{
|
||||
Title = "Lumina API",
|
||||
Version = description.ApiVersion.ToString()
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ internal static class PresentationApiLayerConfiguration
|
||||
/// <exception cref="DirectoryNotFoundException">Thrown when the base path where the configuration files should be located, does not exist.</exception>
|
||||
public static IServiceCollection BindPresentationApiLayerConfiguration(this IServiceCollection services, IConfigurationManager configuration)
|
||||
{
|
||||
var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
string? basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
if (!Directory.Exists(basePath))
|
||||
throw new DirectoryNotFoundException($"The base path '{basePath}' does not exist.");
|
||||
configuration.SetBasePath(basePath);
|
||||
|
||||
+4
-7
@@ -25,14 +25,11 @@ public static class PresentationApiLayerServices
|
||||
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection AddPresentationApiLayerServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll",
|
||||
services.AddCors(options => options.AddPolicy("AllowAll",
|
||||
builder => builder
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader());
|
||||
});
|
||||
.AllowAnyHeader()));
|
||||
|
||||
// add services to the container
|
||||
services.AddControllers().AddJsonOptions(options =>
|
||||
@@ -45,7 +42,7 @@ public static class PresentationApiLayerServices
|
||||
services.AddEndpointsApiExplorer();
|
||||
services.AddSwaggerGen();
|
||||
services.ConfigureOptions<ConfigureSwaggerOptions>();
|
||||
|
||||
|
||||
services.AddApiVersioning(options =>
|
||||
{
|
||||
options.DefaultApiVersion = new ApiVersion(1, 0);
|
||||
@@ -62,7 +59,7 @@ public static class PresentationApiLayerServices
|
||||
services.AddSingleton<ProblemDetailsFactory, CustomProblemDetailsFactory>();
|
||||
|
||||
// register mapster configs
|
||||
var mapsterConfig = TypeAdapterConfig.GlobalSettings;
|
||||
TypeAdapterConfig mapsterConfig = TypeAdapterConfig.GlobalSettings;
|
||||
mapsterConfig.Scan(typeof(PresentationApiLayerServices).Assembly);
|
||||
services.AddSingleton(mapsterConfig);
|
||||
services.AddScoped<IMapper, ServiceMapper>();
|
||||
|
||||
@@ -53,7 +53,7 @@ public class CustomProblemDetailsFactory : ProblemDetailsFactory
|
||||
string? detail = null, string? instance = null)
|
||||
{
|
||||
statusCode ??= 500;
|
||||
var problemDetails = new ProblemDetails
|
||||
ProblemDetails problemDetails = new()
|
||||
{
|
||||
Status = statusCode,
|
||||
Title = title,
|
||||
@@ -81,7 +81,7 @@ public class CustomProblemDetailsFactory : ProblemDetailsFactory
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(modelStateDictionary);
|
||||
statusCode ??= 400;
|
||||
var problemDetails = new ValidationProblemDetails(modelStateDictionary)
|
||||
ValidationProblemDetails problemDetails = new(modelStateDictionary)
|
||||
{
|
||||
Status = statusCode,
|
||||
Type = type,
|
||||
@@ -104,23 +104,20 @@ public class CustomProblemDetailsFactory : ProblemDetailsFactory
|
||||
private void ApplyProblemDetailsDefaults(HttpContext httpContext, ProblemDetails problemDetails, int statusCode)
|
||||
{
|
||||
problemDetails.Status ??= statusCode;
|
||||
if (_options.ClientErrorMapping.TryGetValue(statusCode, out var clientErrorData))
|
||||
if (_options.ClientErrorMapping.TryGetValue(statusCode, out ClientErrorData? clientErrorData))
|
||||
{
|
||||
problemDetails.Title ??= clientErrorData.Title;
|
||||
problemDetails.Type ??= clientErrorData.Link;
|
||||
}
|
||||
var traceId = Activity.Current?.Id ?? httpContext?.TraceIdentifier;
|
||||
string? traceId = Activity.Current?.Id ?? httpContext?.TraceIdentifier;
|
||||
if (traceId != null)
|
||||
problemDetails.Extensions["traceId"] = traceId;
|
||||
// get any errors that might be sent by ApiController base class' Problem() method
|
||||
var errors = httpContext?.Items[HttpContextItemKeys.ERRORS] as List<Error>;
|
||||
List<Error>? errors = httpContext?.Items[HttpContextItemKeys.ERRORS] as List<Error>;
|
||||
// add any extra custom properties
|
||||
if (errors is not null)
|
||||
{
|
||||
problemDetails.Extensions.Add("errors", errors.Select(error =>
|
||||
{
|
||||
return error.Code;
|
||||
}));
|
||||
problemDetails.Extensions.Add("errors", errors.Select(error => error.Code));
|
||||
}
|
||||
//problemDetails.Extensions.Add("errorCodes", errors.Select(e => e.Type.ToString()));
|
||||
_configure?.Invoke(new() { HttpContext = httpContext!, ProblemDetails = problemDetails });
|
||||
|
||||
@@ -23,7 +23,7 @@ public class UrlStringBinder : IModelBinder
|
||||
throw new ArgumentNullException(nameof(bindingContext));
|
||||
string modelName = bindingContext.ModelName;
|
||||
// try to fetch the value of the argument by name
|
||||
var valueProviderResult = bindingContext.ValueProvider.GetValue(modelName);
|
||||
ValueProviderResult valueProviderResult = bindingContext.ValueProvider.GetValue(modelName);
|
||||
if (valueProviderResult == ValueProviderResult.None)
|
||||
return Task.CompletedTask;
|
||||
string? value = valueProviderResult.FirstValue;
|
||||
|
||||
Reference in new issue
Block a user