Schemars
Generate JSON Schema documents directly from Rust types
Repository Health
Technical Analysis
Schemars derives JSON Schema documents from Rust structs and enums with a single #[derive(JsonSchema)] macro, reusing the same field attributes (rename, skip, default) that serde already understands so your schema and your serialization stay in sync automatically. It ships JsonSchema implementations for most of the standard library plus popular crates (chrono, uuid, bytes, indexmap, rust_decimal) behind feature flags.
Because the generated schema is built from actual Rust type definitions rather than hand-written separately, Schemars is commonly used to produce OpenAPI-compatible schemas, validate config files, or describe tool/function-call interfaces for LLM integrations without maintaining a second schema definition by hand.
What You Get
- A
#[derive(JsonSchema)]macro plusschema_for!/schema_for_value!macros for one-line schema generation - Automatic reuse of
serdeattributes (rename,skip_serializing_if,default) so schema and serialization never drift - Built-in
JsonSchemaimplementations for moststdtypes and, via feature flags, chrono, uuid, bytes, indexmap,rust_decimal, and more - A
Generator/SchemaSettingsAPI for customizing schema draft version,$refstrategy, and inline-vs-referenced definitions no_std-compatible core so it can run in embedded or constrained environments
Common Use Cases
- Generating OpenAPI-compatible request/response schemas for a Rust web API (Axum, Actix, Rocket) alongside existing
serdemodels - Producing JSON Schema tool/function definitions for LLM function-calling from native Rust structs
- Validating configuration files against a schema derived straight from the config struct definition
- Publishing a public JSON Schema for a data format defined by a Rust type, without maintaining it by hand
Under The Hood
Architecture: schemars/src/lib.rs defines the JsonSchema trait and re-exports the derive macro from the sibling schemars_derive proc-macro crate; generate.rs and schema.rs implement the actual schema-building logic and settings (draft version, $ref inlining), while json_schema_impls/ provides JsonSchema implementations for every supported type, gated behind per-crate feature flags (chrono04, uuid1, indexmap2, etc.) so consumers only compile in what they use.
Tech Stack: Pure Rust, no_std-compatible core (categories = ["encoding", "no-std"] in Cargo.toml) built on serde/serde_json plus small utility crates (dyn-clone, ref-cast); optional integrations use versioned feature-flag naming (e.g. chrono04, bigdecimal04) to support multiple major versions of dependent crates simultaneously.
Code Quality: The schemars crate ships 61+ integration/unit test files covering type-by-type schema output (including snapshot-style expected-JSON comparisons and an update-tests.sh regeneration script), reflecting the project’s need for byte-stable schema output across releases; clippy.toml enforces lint discipline project-wide.
API Design: The primary entry point is a single derive macro plus one macro call (schema_for!(MyType)), so most users never touch the Generator/SchemaSettings customization API at all — advanced schema-shape control (draft version, $ref policy) is opt-in rather than required, keeping the common case a two-line change to an existing serde-derived struct.
Used by 11 apps in this directory
Svix
Automation · Developer Tools
Open source, self-hostable webhook infrastructure that handles delivery, retries, HMAC signing, and multi-tenant event management so you never have to build a webhooks system from scratch.
Volga
Data Engineering
A Rust-based real-time data processing engine for AI/ML feature computation, built on Apache DataFusion and Arrow — positioned as an alternative to Flink, Spark, Chronon, and OpenMLDB with unified streaming, batch, and request-time execution.