简体   繁体   中英

Does Swashbuckle.AspNetCore support FluentValidation instead of DataAnnotations?

I've been reading the docs for Swashbuckle.AspNetCore and it suggest that you can use DataAnnotation 's to decorate various things to get a richer Swagger API generated. Nice!

But ... we're not using DataAnnotations . We're using FluentValidation instead.

So, does the Swashbuckle.AspNetCore library provide a way to leverage FluentValidation instead DataAnnotations ?

We would prefer not to repeat any validation logic, twice.

Let me expand a bit on my comment:

It would not be too difficult to enhance Swashbuckle to incorporate FluentValidation

I would like to start by saying that FluentValidation has some complicated validation cases, stuff that is probably not even supported by the latest OAS (3.0.1) or the Swagger-UI, so my comment is about the most common stuff...

Your best leverage here is that both projects are OpenSource, you could:

  • Incorporate FluentValidation into Swashbuckle
  • Enhance FluentValidation to inject DataAnnotations as part of the rules

Let's be clear none of those are a 5 hour quick code fix...
But if I was going to do the job, I think that the second is a better option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM