This is a simple use case:
#!/usr/bin/env dotnet
#:sdk Microsoft.NET.Sdk.Web
#:package FluentValidation.AspNetCore@*
#:package MicroElements.Swashbuckle.FluentValidation@*
#:package Swashbuckle.AspNetCore@*
#:property PublishAot=false
#:property ManagePackageVersionsCentrally=false
using System.Reflection;
using FluentValidation;
using FluentValidation.AspNetCore;
using MicroElements.Swashbuckle.FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer().AddControllers()
.ConfigureApiBehaviorOptions(options =>
{
options.SuppressInferBindingSourcesForParameters = true;
})
.Services
.AddSwaggerGen()
.AddFluentValidationAutoValidation()
.AddFluentValidationClientsideAdapters()
.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly())
.AddFluentValidationRulesToSwagger(o => o.UseAllOfForMultipleRules = false);
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.MapControllers();
app.Run();
[ApiController]
public sealed class ApiController : ControllerBase
{
[HttpGet("/api/hello")]
public string Hello(HelloRequest request) => $"Hello {request.Name ?? "world"}!";
[HttpGet("/api/hello2")]
public string HelloTwo(HelloRequest request) => $"Hello {request.Name ?? "world"}!";
}
public sealed class HelloRequest
{
[FromQuery]
public string? Name { get; set; }
}
public sealed class HelloRequestValidator : AbstractValidator<HelloRequest>
{
public HelloRequestValidator()
{
RuleFor(x => x.Name)
.NotEmpty()
.MaximumLength(10);
}
}
I like to put the RemoveUnusedQuerySchemas = true but finally I put it as false because I am losing the FluentValidationRules on the migration from version 6.0.0.0 to 7.1.8
I am happy to contribute anyway
This is a simple use case:
I like to put the RemoveUnusedQuerySchemas = true but finally I put it as false because I am losing the FluentValidationRules on the migration from version 6.0.0.0 to 7.1.8
I am happy to contribute anyway