Adding support for FluentValidations and swagger schema.
See original GitHub issueI wish to register FluentValidation rules, so that they show up in swagger schema. Given the sample code below:
public class Validator : AbstractValidator<ClosureScheduleCommand>
{
public Validator()
{
RuleFor(x => x.Warehouse).NotEmpty();
}
}
We should be able to correctly mark the property as required. Example of the wanted schema presentation in Swagger The required field is marked by a red asterix. In this example i relied on the attribute [JsonRequired]
Similar implementations in MVC aspnetcore 3.1:
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:17 (10 by maintainers)
Top Results From Across the Web
Adding support for FluentValidations and swagger schema.
I wish to register FluentValidation rules, so that they show up in swagger schema. Given the sample code below: public class Validator ...
Read more >Fluent Validation with Swagger in Asp.net Core
I've created github project and nuget package based on Mujahid Daud Khan answer. I made redesign to support extensibility and supported ...
Read more >Making FluentValidation compatible with Swagger ...
Building Swagger schema based on FluentValdation rules The schemaModel has some predefined structure, on which properties have to be set based ...
Read more >How to Generate API Client Code Using NSwag ...
Get started with NSwag and ASP.NET Core by using FluentValidation rules to define Swagger schema in ASP.NET Core API.
Read more >Fluent Validation with Swagger in Asp.net Core
So far i have tried the following code but i am unable to get validator type. services.AddSwaggerGen(options => options.SchemaFilter<AddFluentValidationRules>() ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After some discussion with @dj-nitehawk we will keep the current support for a single validator against the request type of the endpoint. We will not make complex things injecting base validators automatically that could break the surface api or make things too complex.
Of course the requestDto can use inheritance and it will play nice with both the validator and the swagger support.
So, in case anyone needs to reuse a validator from a base type, he/she can use inheritance in the validator like this:
I am also highly interested in that feature 👍🏼