Expand description
§omni-schema
Universal Schema Generator for Rust - One source of truth, multiple outputs.
omni-schema generates multiple schema formats from a single Rust struct/enum
definition using derive macros. Define your types once, export to JSON Schema,
OpenAPI, GraphQL, Protocol Buffers, TypeScript, and Avro.
§Quick Start
Add omni-schema to your Cargo.toml:
[dependencies]
omni-schema = { version = "0.1", features = ["all-formats"] }Then use the Schema derive macro:
ⓘ
use omni_schema::Schema;
use std::collections::HashMap;
#[derive(Schema)]
#[schema(description = "A user in the system")]
pub struct User {
#[schema(description = "Unique identifier")]
pub id: u64,
#[schema(min_length = 1, max_length = 100)]
pub name: String,
#[schema(format = "email")]
pub email: String,
pub tags: Vec<String>,
}
#[derive(Schema)]
pub enum Status {
Active,
Inactive,
Suspended { reason: String },
}Generate schemas:
ⓘ
use omni_schema::prelude::*;
// Generate JSON Schema
let json_schema = User::json_schema();
// Generate TypeScript types
let typescript = User::typescript_type();
// Generate GraphQL SDL
let graphql = User::graphql_sdl();
// Generate Protocol Buffers
let proto = User::proto_definition();§Batch Export with Registry
For exporting multiple types together:
ⓘ
use omni_schema::{Schema, SchemaRegistry};
let registry = SchemaRegistry::new()
.register::<User>()
.register::<Status>()
.with_title("My API")
.with_version("1.0.0");
// Export to files
registry.export_json_schema("./schemas/json/").unwrap();
registry.export_typescript("./schemas/types.ts").unwrap();
registry.export_graphql("./schemas/schema.graphql").unwrap();
registry.export_proto("./schemas/models.proto").unwrap();§Feature Flags
json-schema- JSON Schema generation (default)openapi- OpenAPI 3.1 generationgraphql- GraphQL SDL generationprotobuf- Protocol Buffers generationtypescript- TypeScript type generationavro- Apache Avro schema generationall-formats- All format generatorsuuid-support- UUID type supportchrono-support- DateTime type supporturl-support- URL type supportserde-compat- Serde attribute compatibilityfull- Everything enabled
Re-exports§
pub use serde_json;
Modules§
Structs§
- Enum
Attribute - Enum
Definition - Enum
Variant - Field
Attribute - Field
Definition - Newtype
Definition - Registry
Config - Schema
Attributes - Schema
Definition - Schema
Registry - Struct
Definition - Struct
Field - Type
Attribute - Variant
Attribute
Enums§
Traits§
- External
Schema - Trait for providing custom schema implementations for external types.
- Flattenable
Schema - Trait for types that can be flattened into their parent struct.
- Schema
Impl - The main trait for types that can generate schema definitions.