Add one long hierarchical method, change some return codes

This commit is contained in:
2025-10-09 20:30:39 +03:00
parent 96a5e764c2
commit 30cb0521f6
8 changed files with 108 additions and 11 deletions

View File

@@ -2,6 +2,8 @@ using System.Net;
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json.Converters;
@@ -22,8 +24,34 @@ public class Program
builder.Services.AddAuthorization();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddControllers().AddNewtonsoftJson(
options => options.SerializerSettings.Converters.Add(new StringEnumConverter()));
builder.Services.AddControllers()
.AddNewtonsoftJson(
options => options.SerializerSettings.Converters.Add(new StringEnumConverter()))
/*.ConfigureApiBehaviorOptions(opt =>
{
opt.InvalidModelStateResponseFactory = context =>
{
var problemDetails = new ValidationProblemDetails(context.ModelState);
var isBindingError = context.ModelState.Values.Any(v =>
v.ValidationState == ModelValidationState.Invalid && v.Errors.Any(e =>
e.Exception is not null || (!string.IsNullOrWhiteSpace(e.ErrorMessage) && e.ErrorMessage.Contains("body is required."))
));
if (isBindingError)
{
problemDetails.Status = StatusCodes.Status400BadRequest;
return new BadRequestObjectResult(problemDetails);
}
problemDetails.Status = StatusCodes.Status422UnprocessableEntity;
var result = new ObjectResult(problemDetails)
{
StatusCode = StatusCodes.Status422UnprocessableEntity,
};
result.ContentTypes.Add("application/json");
return result;
};
})*/;
builder.Services.AddOpenApiDocument(cfg =>
{
cfg.OperationProcessors.Add(new OperationSecurityScopeProcessor("auth"));