Integrates FluentValidation rules with Swashbuckle to automatically generate accurate OpenAPI/Swagger schemas.
MicroElements.Swashbuckle.FluentValidation is a .NET library that automatically generates OpenAPI (Swagger) documentation from FluentValidation rules. It replaces the need for manual `ComponentModel` attributes by translating validation logic—such as required fields, email formats, or numeric ranges—into accurate API schemas. This ensures developers' Swagger documentation always matches their actual validation constraints.
.NET developers building ASP.NET Core Web APIs or Minimal APIs who use FluentValidation for input validation and Swashbuckle for OpenAPI documentation.
It eliminates duplication between validation logic and API documentation by automatically inferring schema rules from FluentValidation, reducing maintenance overhead and preventing discrepancies. The extensible rule system allows customization for complex validation scenarios.
Use FluentValidation rules instead of ComponentModel attributes
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Translates FluentValidation rules like NotNull and EmailAddress into OpenAPI constraints automatically, eliminating the need for duplicate ComponentModel attributes and ensuring documentation accuracy.
Supports custom FluentValidationRule implementations, allowing developers to define or override mappings for specialized validators, as shown in the extensibility section.
Integrates with ASP.NET Core via AddFluentValidationRulesToSwagger, requiring minimal setup for both Minimal APIs and traditional WebApi projects with just a few lines of code.
Capably processes validators that use Include to compose rules from multiple sources, ensuring comprehensive schema coverage without manual intervention.
Common issues with scoped services can lead to runtime errors like 'Cannot resolve IValidator', requiring workarounds such as UseScopedSwagger or disabling scope validation.
For float and double validators, the library admits that Swashbuckle's schema generation loses fraction parts, limiting accuracy in numeric range documentation as noted in the samples.
Strict version matching with Swashbuckle and FluentValidation, detailed in a compatibility table, can complicate upgrades or lock projects into specific dependency versions.