简体   繁体   English

Swashbuckle.AspNetCore是否支持FluentValidation而不是DataAnnotations?

[英]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. 我一直在阅读Swashbuckle.AspNetCore的文档,它建议您可以使用DataAnnotation来装饰各种东西,以生成更丰富的Swagger API。 Nice! 太好了!

But ... we're not using DataAnnotations . 但是...我们没有使用DataAnnotations We're using FluentValidation instead. 我们改用FluentValidation

So, does the Swashbuckle.AspNetCore library provide a way to leverage FluentValidation instead DataAnnotations ? 那么, Swashbuckle.AspNetCore库是否提供一种利用FluentValidation代替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 增强Swashbuckle以并入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... 首先,我要说FluentValidation有一些复杂的验证案例,这些东西甚至可能不受最新的OAS(3.0.1)或Swagger-UI的支持,所以我的评论是关于最常见的东西...

Your best leverage here is that both projects are OpenSource, you could: 最好的利用是,这两个项目都是OpenSource,您可以:

  • Incorporate FluentValidation into Swashbuckle 将FluentValidation整合到Swashbuckle中
  • Enhance FluentValidation to inject DataAnnotations as part of the rules 增强FluentValidation以将DataAnnotations插入为规则的一部分

Let's be clear none of those are a 5 hour quick code fix... 让我们清楚一点,这些都不是5小时的快速代码修复...
But if I was going to do the job, I think that the second is a better option. 但是,如果我打算做这份工作,我认为第二个是更好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 可选参数在Swashbuckle.AspNetCore中导致空异常 - Optional parameter causes null exception in Swashbuckle.AspNetCore Swashbuckle.AspNetCore-无法为继承基本控制器的控制器生成json - Swashbuckle.AspNetCore - Unable to generate json for controllers that inherit base controllers 迁移到 Swashbuckle.AspNetCore 版本 5 时,Swagger UI 中的不记名身份验证 - Bearer authentication in Swagger UI, when migrating to Swashbuckle.AspNetCore version 5 Swashbuckle.AspNetCore openapi 架构中未正确显示可空属性 - Nullable property is not presented in the Swashbuckle.AspNetCore openapi schema properly 多版本控制 URL 在 Swashbuckle.AspNetCore 5.0.0rc 中不起作用 - Multiple versioning URL not working in Swashbuckle.AspNetCore 5.0.0rc Swashbuckle.AspNetCore (5.0.0-rc5) 忽略公共字段 - Swashbuckle.AspNetCore (5.0.0-rc5) ignoring public fields 如何使用Swashbuckle.AspNetCore隐藏响应代码200? - How can I hide response code 200 with Swashbuckle.AspNetCore? swashbuckle.aspnetcore 是否支持 asp.net core 3.0? - Is swashbuckle.aspnetcore supporting asp.net core 3.0? Swashbuckle.AspNetCore仅生成带有字符串类型字段的模型 - Swashbuckle.AspNetCore only generating models with fields of type string 带OAuth应用程序流的SwashBuckle.AspNetCore 4.1? - SwashBuckle.AspNetCore 4.1 w/ OAuth application flow?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM