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
AppFlowy
Productivity · Project Management · Collaboration
The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.
Arroyo
Data Engineering · Analytics
A distributed stream processing engine written in Rust that lets you write SQL to run stateful, real-time computations over data streams with subsecond results.
Cap
Team Chat · Video Conferencing
Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.
fabro
Developer Tools · Devops
Define AI agent workflows as code graphs, route tasks across any LLM, and intervene only where it matters.
herdr
AI Agents · Developer Tools
A terminal-native agent multiplexer that runs Claude, Codex, Gemini, and other coding agents side by side in real, persistent panes you can detach from and reattach to from anywhere.
iii
Developer Tools · Devops
Compose, extend, and observe every backend service in real time using three primitives: Workers, Functions, and Triggers.
Laminar
AI Development · Monitoring
Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.
mesh-llm
AI Development · AI Agents
Mesh LLM pools GPUs and memory across every machine you own into one OpenAI-compatible API, so agents tap distributed compute instead of a single GPU box or a metered cloud bill.
Silex
No Code Platforms · Design Tools
Free, open-source visual website builder that exports clean HTML/CSS — no lock-in, no subscription, host anywhere