Extensions.FluentValidation.Schema 1.0.2

dotnet add package Extensions.FluentValidation.Schema --version 1.0.2
                    
NuGet\Install-Package Extensions.FluentValidation.Schema -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Extensions.FluentValidation.Schema" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Extensions.FluentValidation.Schema" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Extensions.FluentValidation.Schema" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Extensions.FluentValidation.Schema --version 1.0.2
                    
#r "nuget: Extensions.FluentValidation.Schema, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Extensions.FluentValidation.Schema@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Extensions.FluentValidation.Schema&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Extensions.FluentValidation.Schema&version=1.0.2
                    
Install as a Cake Tool

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 Extensions.FluentValidation.Schema

Or via NuGet Package Manager:

Install-Package Extensions.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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 99 11/29/2025
1.0.1 96 11/29/2025