create-validator

Generates FluentValidation validator classes co-located with DTOs and ViewModels in C#.

Updated Nov 19, 2020
One-click install
npx skills add https://github.com/kwojtasinski-repo/ECommerceApp --skill create-validator-kwojtasinski-repo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: create-validator
Source: https://github.com/kwojtasinski-repo/ECommerceApp/tree/main/.github/skills/create-validator
Command: npx skills add https://github.com/kwojtasinski-repo/ECommerceApp --skill create-validator-kwojtasinski-repo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing FluentValidation validators by hand is repetitive and error-prone: rules must match DTO properties, string lengths must align with EF Core HasMaxLength configurations, and naming conventions must stay consistent. This Skill scaffolds a correct AbstractValidator<T> directly in the same file as the DTO or ViewModel it validates. ## Core Features & Use Cases - Simple property rules: Generates NotNull, NotEmpty, length, range, and email rules matched to each property type. - Conditional and collection validation: Supports When blocks, RuleForEach with ChildRules, and nested DTO composition via SetValidator. - Wrapper ViewModel validators: Defers to the inner DTO's validator when a ViewModel wraps a DTO. - Use Case: You add a new CreateOrderDto with customer, items, and price fields. Invoke the Skill to append a CreateOrderDtoValidation class in the same file, with rules matching every required property and EF string-length constraints. ## Quick Start Ask the AI to create a FluentValidation validator for a named DTO or ViewModel, optionally specifying the bounded context, for example: create a validator for CreateOrderDto in the Orders bounded context.

Frequently Asked Questions about create-validator

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a FluentValidation validator for a C# DTO?

Create a class inheriting AbstractValidator<T> and define RuleFor expressions in the constructor for each property. This Skill generates the validator in the same file as the DTO, using the Validation suffix naming convention.

How to validate a collection of items with FluentValidation?

Use RuleForEach(x => x.Items).ChildRules(item => { ... }) to define rules for each element in a collection. Wrap it in a When block if the collection may be null or empty.

Does FluentValidation require manual DI registration for validators?

No. Validators are auto-discovered when the application calls AddFluentValidation with RegisterValidatorsFromAssembly, so no manual dependency injection registration is needed for each validator class.

How do I validate a nested DTO inside a ViewModel with FluentValidation?

Use RuleFor(x => x.InnerProperty).SetValidator(new InnerDtoValidation()) to delegate validation of the nested object to its own validator. This keeps each validator focused on a single type.

Why should FluentValidation string lengths match EF Core configuration?

Matching MaximumLength rules to the entity's HasMaxLength configuration ensures invalid input is rejected before reaching the database. This prevents truncation errors and keeps validation messages consistent with storage constraints.