| 1 | use schemars::schema_for_value; |
| 2 | use serde::Serialize; |
| 3 | |
| 4 | #[derive(Serialize)] |
| 5 | pub struct MyStruct { |
| 6 | pub my_int: i32, |
| 7 | pub my_bool: bool, |
| 8 | pub my_nullable_enum: Option<MyEnum>, |
| 9 | } |
| 10 | |
| 11 | #[derive(Serialize)] |
| 12 | pub enum MyEnum { |
| 13 | StringNewType(String), |
| 14 | StructVariant { floats: Vec<f32> }, |
| 15 | } |
| 16 | |
| 17 | fn main() { |
| 18 | let schema = schema_for_value!(MyStruct { |
| 19 | my_int: 123, |
| 20 | my_bool: true, |
| 21 | my_nullable_enum: Some(MyEnum::StringNewType("foo".to_string())) |
| 22 | }); |
| 23 | println!("{}", serde_json::to_string_pretty(&schema).unwrap()); |
| 24 | } |