v1.5.0
What's Changed
This release adds flexible validation error handling for class-validator / NestJS ValidationPipe, shipped via a new optional subpath export nest-problem-details-filter/class-validator-mappers. It supports three progressively more structured approaches — from zero-config string arrays to full RFC 9457 JSON Pointer compliance — without breaking existing consumers.
Features
-
Validation error mapping helpers (#34) — new
nest-problem-details-filter/class-validator-mapperssubpath export with three utilities:Field-map approach — per-field
Record<string, string[]>with dotted-path nesting:import { mapClassValidatorErrors } from 'nest-problem-details-filter/class-validator-mappers'; new ValidationPipe({ exceptionFactory: (e) => new BadRequestException({ message: 'Validation failed', errors: mapClassValidatorErrors(e), }), });
JSON Pointer approach — strict RFC 9457 compliance with
pointerarrays:import { mapToPointerErrors } from 'nest-problem-details-filter/class-validator-mappers'; new ProblemDetailsException({ status: 400, title: 'Validation Failed', type: 'validation-error', errors: mapToPointerErrors(e), });
One-liner shorthand —
toValidationProblemDetails()wraps the field-map or pointer logic and returns a ready-to-throwProblemDetailsException:import { toValidationProblemDetails } from 'nest-problem-details-filter/class-validator-mappers'; // Field-map (default) new ValidationPipe({ exceptionFactory: (e) => toValidationProblemDetails(e), }); // RFC 9457 JSON Pointer array new ValidationPipe({ exceptionFactory: (e) => toValidationProblemDetails(e, { usePointers: true }), });
All helpers use the real
class-validatorValidationErrortype (no duck-typing), flatten nested objects (e.g.address.street), and surface custom validator messages alongside built-in constraints. -
errorsextension member support —HttpExceptionFilternow detectsstring[]messages from Nest's defaultValidationPipeand places them in theerrorsfield (per RFC 9457 §3.1.4), instead of concatenating intodetail. It also passes through expliciterrorsobjects from customexceptionFactoryimplementations. -
IExceptionResponserelaxed message type —messagenow acceptsstring | string[], matching NestJSHttpExceptionruntime behavior and the defaultValidationPipeoutput shape. -
class-validatoras optional peer dependency — declared inpeerDependenciesMetaso the core filter remains zero-runtime-dependency. Users who opt into validation helpers installclass-validatoralongside the filter. -
Comprehensive test coverage — 253 tests, 100% coverage across all metrics, including nested DTO flattening and custom
registerDecoratorvalidators in both Express and Fastify integration suites. -
Dev mock server + OpenAPI playground (#33) —
pnpm run dev:mockspins up a local NestJS app with all problem detail endpoints exposed; Swagger UI auto-documents@ApiProblemResponseand the new validation examples.
Fixes
- Import path consistency — corrected stale
nest-problem-details-filter/class-validatorpaths in README anddocs/usage.mdto the finalnest-problem-details-filter/class-validator-mapperssubpath.
Changes
src/validation→src/class-validator-mappers— directory renamed for clarity; the old name implied built-in validation logic rather than optional mapping helpers.src/index.tscleanup — validation helpers removed from the main barrel export to avoid forcing theclass-validatortype dependency on consumers who don't need it.- Documentation — README and
docs/usage.mdupdated with a dedicated "Validation errors" section covering all three approaches (default array, field-map viaBadRequestException, andProblemDetailsExceptionwith or without JSON Pointers).
Full Changelog: v1.4.0...v1.5.0