postmortem
Learn what went wrong—all at once.
A validation library that accumulates all validation errors instead of short-circuiting on the first failure.
Why "postmortem"?
In software, a postmortem is what you do after something breaks—gathering all the evidence to understand what went wrong. Traditional validation libraries give you the frustrating experience of fixing one error only to discover another:
Validation failed: email is required
# fix email...
Validation failed: age must be >= 18
# fix age...
Validation failed: password too short
postmortem gives you the complete picture upfront:
Validation errors (3):
$.email: missing required field
$.age: value 15 must be >= 18
$.password: length 5 is less than minimum 8
One validation run. All errors. Complete feedback for fixing what went wrong.
Features
- Accumulate all errors — Never stop at the first problem
- Composable schemas — Build complex validators from simple primitives
- Type-safe — Leverage Rust's type system
- JSON path tracking — Know exactly which field failed (e.g.,
users[0].email) - Schema registry — Define reusable schemas with references
- Cross-field validation — Validate relationships between fields
- Recursive schemas — Support for self-referential data structures
Quick Start
use ;
use json;
// Build a validation schema
let user_schema = object
.required
.required
.required;
// Validate data - accumulates ALL errors
let data = json!;
let result = user_schema.validate;
// Handle accumulated errors
match result
Installation
[]
= "0.1"
Core Concepts
Schema Types
Build validation schemas using a fluent API:
// String validation
let name = string
.min_len
.max_len
.pattern;
// Integer validation
let age = integer
.min
.max;
// Array validation
let tags = array
.min_items
.max_items
.items;
// Object validation
let user = object
.required
.optional;
Schema Combinators
Combine schemas for complex validation logic:
// One of multiple schemas
let id = one_of;
// All schemas must pass
let strict_string = all_of;
// Exactly one schema must pass (XOR)
let payment = exactly_one_of;
Schema Registry and References
Define reusable schemas with references:
use SchemaRegistry;
let mut registry = new;
// Define a reusable schema
registry.define;
// Reference it in other schemas
let person = object
.required
.required
.required;
// Validate with the registry
let result = registry.validate;
JSON Path Tracking
Every error includes the exact path to the failing field:
let data = json!;
let schema = array.items;
let result = schema.validate;
// Errors at: users[1].email and users[3].email
Cross-Field Validation
Validate relationships between fields:
let schema = object
.required
.required
.custom;
Design Philosophy
postmortem is built on functional programming principles:
- Pure validation — Schemas are immutable, validation has no side effects
- Composition — Build complex validators from simple primitives
- Error accumulation — Uses applicative functors (stillwater's
Validationtype) to collect all errors
This design makes schemas:
- Easy to test in isolation
- Safe to use concurrently (schemas are
Send + Sync) - Simple to compose and reuse
Documentation
Full API documentation is available at docs.rs/postmortem.
License
MIT — Glen Baker iepathos@gmail.com