use domainstack::Validate;
#[derive(Debug, Validate)]
pub struct Email(#[validate(email)] pub String);
#[derive(Debug, Validate)]
pub struct Age(#[validate(range(min = 0, max = 150))] pub u8);
#[derive(Debug, Validate)]
pub struct Username(
#[validate(alphanumeric)]
#[validate(length(min = 3, max = 30))]
pub String,
);
#[derive(Debug, Validate)]
pub struct Url(#[validate(url)] pub String);
#[derive(Debug, Validate)]
pub struct PhoneNumber(#[validate(matches_regex = r"^\+?[1-9]\d{1,14}$")] pub String);
#[derive(Debug, Validate)]
pub enum PaymentMethod {
Cash,
CreditCard {
#[validate(length(min = 13, max = 19))]
#[validate(numeric_string)]
card_number: String,
#[validate(range(min = 1, max = 12))]
exp_month: u8,
#[validate(range(min = 2024, max = 2040))]
exp_year: u16,
#[validate(length(min = 3, max = 4))]
#[validate(numeric_string)]
cvv: String,
},
PayPal(#[validate(email)] String),
BankTransfer {
#[validate(alphanumeric)]
#[validate(length(min = 5, max = 34))]
account_number: String,
#[validate(length(min = 6, max = 11))]
routing_number: String,
},
}
#[derive(Debug, Validate)]
pub enum ContactPreference {
Email(#[validate(email)] String),
Phone(#[validate(matches_regex = r"^\+?[0-9]{10,15}$")] String),
Sms(#[validate(matches_regex = r"^\+?[0-9]{10,15}$")] String),
None,
}
#[derive(Debug, Validate)]
pub enum OrderStatus {
Pending,
Processing,
Shipped,
Delivered,
Cancelled,
Refunded,
}
#[derive(Debug, Validate)]
pub enum ProductCategory {
Electronics,
Clothing,
Books,
HomeAndGarden,
Sports,
Toys,
Food,
Other(#[validate(length(min = 2, max = 50))] String),
}
#[derive(Debug, Validate)]
pub struct UserProfile {
#[validate(email)]
#[validate(max_len = 255)]
pub email: String,
#[validate(length(min = 3, max = 50))]
#[validate(alphanumeric)]
pub username: String,
#[validate(length(min = 1, max = 100))]
pub display_name: String,
#[validate(range(min = 13, max = 120))]
pub age: u8,
}
#[derive(Debug, Validate)]
pub struct Address {
#[validate(length(min = 1, max = 100))]
pub street_line_1: String,
pub street_line_2: Option<String>,
#[validate(length(min = 2, max = 50))]
pub city: String,
#[validate(length(min = 2, max = 50))]
pub state: String,
#[validate(matches_regex = r"^[0-9]{5}(-[0-9]{4})?$")]
pub postal_code: String,
#[validate(length(min = 2, max = 2))]
pub country_code: String,
}
#[derive(Debug, Validate)]
pub struct Product {
#[validate(length(min = 1, max = 200))]
pub name: String,
pub description: Option<String>,
#[validate(positive)]
pub price: f64,
#[validate(range(min = 0, max = 1000000))]
pub stock_quantity: u32,
pub tags: Vec<String>,
}
#[derive(Debug, Validate)]
pub struct CartItem {
#[validate(length(min = 1, max = 50))]
pub product_id: String,
#[validate(range(min = 1, max = 100))]
pub quantity: u32,
#[validate(positive)]
pub unit_price: f64,
}
#[derive(Debug, Validate)]
pub struct CreateUserRequest {
#[validate(email)]
#[validate(max_len = 255)]
pub email: String,
#[validate(alphanumeric)]
#[validate(length(min = 3, max = 30))]
pub username: String,
#[validate(length(min = 8, max = 128))]
pub password: String,
#[validate(range(min = 0, max = 150))]
pub age: u8,
pub website: Option<String>,
}
#[derive(Debug, Validate)]
pub struct CreateUserResponse {
#[validate(length(min = 1, max = 50))]
pub user_id: String,
#[validate(email)]
pub email: String,
#[validate(alphanumeric)]
pub username: String,
#[validate(url)]
pub profile_url: String,
}
fn main() {
println!("JSON Schema Demo Types");
println!("======================");
println!();
println!("This file contains example types for JSON Schema generation.");
println!();
println!("To generate JSON Schema, run:");
println!(" domainstack json-schema --input examples --output schema.json --verbose");
println!();
println!("Types included:");
println!(" - Tuple structs: Email, Age, Username, Url, PhoneNumber");
println!(" - Enums: PaymentMethod, ContactPreference, OrderStatus, ProductCategory");
println!(" - Named structs: UserProfile, Address, Product, CartItem");
println!(" - API types: CreateUserRequest, CreateUserResponse");
}