Like serde, but for structure instead of serialization.
Turn Rust types into JSON schemas that describe their shape. Works with Claude AI tools, OpenAPI specs, or anything else that needs to understand your data structure.
#[derive(Schema)]
struct User { name: String, age: u32 }
User::schema() // → JSON schema describing the structureuse schema::Schema;
#[derive(Schema)]
struct User {
name: String,
age: u32,
email: Option<String>,
}
let schema = User::schema();- schema - Core derive macro
- schema-anthropic - Anthropic Claude tool schemas
- schema-openapi - OpenAPI 3.0 specs
use schema::Schema;
use schema_anthropic::to_tool_schema;
#[derive(Schema)]
struct SearchFiles {
/// Query to search for
query: String,
/// Maximum results to return
limit: Option<u32>,
}
let tool = to_tool_schema::<SearchFiles>("search_files");
// Use with Claude APIuse schema::Schema;
use schema_openapi::to_openapi_schema;
#[derive(Schema)]
struct CreateUser {
username: String,
email: String,
}
let spec = to_openapi_schema::<CreateUser>();
// Returns OpenAPI 3.0 schema object#[derive(Schema)]
enum Status {
Active,
Inactive,
Pending,
}
#[derive(Schema)]
enum Message {
Text { content: String },
Image { url: String, width: u32 },
}- Derives from Rust types
- Doc comments → descriptions
Option<T>→ optional fields- Enums → string enums or tagged unions
- Nested structs supported
#[schema(skip)]to skip fields
[dependencies]
schema = { git = "https://github.com/andrewgazelka/schema" }
schema-anthropic = { git = "https://github.com/andrewgazelka/schema" }
schema-openapi = { git = "https://github.com/andrewgazelka/schema" }MIT