3

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.

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
  • I don't think so. `DataAnnotations` is default built-in set of attributes, and fluent validation is one of many third party libraries. Plus, it's not that easy to find corresponding fluent validators for given entity and analyze them at runtime (compared to attribute-based validation). – Evk May 14 '18 at 06:43
  • It would not be too difficult to enhance Swashbuckle to incorporate FluentValidation, the project is Open Source, you should consider sending a PR or opening an Issue see what the owner says about that – Helder Sepulveda May 14 '18 at 18:05

2 Answers2

0

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.

Helder Sepulveda
  • 15,500
  • 4
  • 29
  • 56