| 1 | use schemars::{schema_for, JsonSchema}; |
| 2 | |
| 3 | #[derive(JsonSchema)] |
| 4 | pub struct MyStruct { |
| 5 | #[validate(range(min = 1, max = 10))] |
| 6 | pub my_int: i32, |
| 7 | pub my_bool: bool, |
| 8 | #[validate(required)] |
| 9 | pub my_nullable_enum: Option<MyEnum>, |
| 10 | } |
| 11 | |
| 12 | #[derive(JsonSchema)] |
| 13 | pub enum MyEnum { |
| 14 | StringNewType(#[validate(email)] String), |
| 15 | StructVariant { |
| 16 | #[validate(length(min = 1, max = 100))] |
| 17 | floats: Vec<f32>, |
| 18 | }, |
| 19 | } |
| 20 | |
| 21 | fn main() { |
| 22 | let schema = schema_for!(MyStruct); |
| 23 | println!("{}", serde_json::to_string_pretty(&schema).unwrap()); |
| 24 | } |