Extensions.FluentValidation.Schema
1.0.1
See the version list below for details.
dotnet add package Extensions.FluentValidation.Schema --version 1.0.1
NuGet\Install-Package Extensions.FluentValidation.Schema -Version 1.0.1
<PackageReference Include="Extensions.FluentValidation.Schema" Version="1.0.1" />
<PackageVersion Include="Extensions.FluentValidation.Schema" Version="1.0.1" />
<PackageReference Include="Extensions.FluentValidation.Schema" />
paket add Extensions.FluentValidation.Schema --version 1.0.1
#r "nuget: Extensions.FluentValidation.Schema, 1.0.1"
#:package Extensions.FluentValidation.Schema@1.0.1
#addin nuget:?package=Extensions.FluentValidation.Schema&version=1.0.1
#tool nuget:?package=Extensions.FluentValidation.Schema&version=1.0.1
FluentValidation.Schema
FluentValidation.Schema generates JSON schemas from FluentValidation rules, ensuring consistent validation on both client- and server-side. Highly customizable and extensible, it bridges the gap between backend and frontend validation logic.
Features
- Converts FluentValidation rules to JSON Schema automatically
- Supports a wide range of validators out-of-the-box
- Ensures consistent input validation across client and server
- Extensible for custom converters
- Reduces duplication and validation errors
Installation
Using .NET CLI:
dotnet add package FluentValidation.Schema
Or via NuGet Package Manager:
Install-Package FluentValidation.Schema
Usage
Define a Validator
public class CustomerValidator : CustomAbstractionValidator<Customer>
{
public CustomerValidator()
{
RuleFor(c => c.Id)
.GreaterThan(0)
.WithMessage("Customer ID must be greater than 0.");
RuleFor(c => c.Surname)
.NotEmpty()
.WithMessage("Surname is required.")
.MaximumLength(50)
.WithMessage("Surname cannot exceed 50 characters.");
RuleFor(c => c.Forename)
.NotEmpty()
.WithMessage("Forename is required.")
.MaximumLength(50)
.WithMessage("Forename cannot exceed 50 characters.");
RuleFor(c => c.Discount)
.InclusiveBetween(0, 100)
.WithMessage("Discount must be between 0 and 100.");
RuleFor(c => c.Address)
.MaximumLength(200)
.WithMessage("Address cannot exceed 200 characters.");
}
}
public class Customer
{
public int Id { get; set; }
public string Surname { get; set; }
public string Forename { get; set; }
public decimal Discount { get; set; }
public string Address { get; set; }
}
Generate JSON Schema
var validator = new CustomerValidator();
Console.WriteLine(validator.GetJsonSchema());
Supported Converters
The library supports the following FluentValidation converters out-of-the-box:
- EmailValidatorSchemaConverter
- ExactLengthValidatorSchemaConverter
- InclusiveBetweenValidatorSchemaConverter
- LengthValidatorSchemaConverter
- MaximumLengthValidatorSchemaConverter
- MinimumLengthValidatorSchemaConverter
- NotEmptyValidatorSchemaConverter
- NotNullValidationSchemaConverter
- RegularExpressionValidatorSchemaConverter
- EqualValidatorSchemaConverter
- NotEqualValidatorSchemaConverter
- LessThanValidatorSchemaConverter
- GreaterThanValidatorSchemaConverter
- GreaterThanOrEqualValidatorSchemaConverter
- LessThanOrEqualValidatorSchemaConverter
Custom converters can also be added for more complex scenarios.
Sample Output
{
"Id": [
{
"ErrorMessage": "Customer ID must be greater than 0.",
"Type": "GreaterThan",
"ValueToCompare": 0
}
],
"Surname": [
{
"ErrorMessage": "Surname is required.",
"Type": "NotEmpty"
},
{
"ErrorMessage": "Surname cannot exceed 50 characters.",
"Type": "MaximumLength",
"Value": 50
}
],
"Forename": [
{
"ErrorMessage": "Forename is required.",
"Type": "NotEmpty"
},
{
"ErrorMessage": "Forename cannot exceed 50 characters.",
"Type": "MaximumLength",
"Value": 50
}
],
"Discount": [
{
"ErrorMessage": "Discount must be between 0 and 100.",
"Type": "InclusiveBetween",
"From": 0,
"To": 100
}
],
"Address": [
{
"ErrorMessage": "Address cannot exceed 200 characters.",
"Type": "MaximumLength",
"Value": 200
}
]
}
Contributing
Contributions are welcome! You can:
- Add new converters for additional FluentValidation rules
- Improve existing schema generation
- Report bugs or request features
License
MIT License — free to use, modify, and distribute.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- FluentValidation (>= 12.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.