| 1 | use schemars::{schema_for, JsonSchema}; |
| 2 | |
| 3 | /// # My Amazing Struct |
| 4 | /// This struct shows off generating a schema with |
| 5 | /// a custom title and description. |
| 6 | #[derive(JsonSchema)] |
| 7 | pub struct MyStruct { |
| 8 | /// # My Amazing Integer |
| 9 | pub my_int: i32, |
| 10 | /// This bool has a description, but no title. |
| 11 | pub my_bool: bool, |
| 12 | /// # A Nullable Enum |
| 13 | /// This enum might be set, or it might not. |
| 14 | pub my_nullable_enum: Option<MyEnum>, |
| 15 | } |
| 16 | |
| 17 | /// # My Amazing Enum |
| 18 | #[derive(JsonSchema)] |
| 19 | pub enum MyEnum { |
| 20 | /// A wrapper around a `String` |
| 21 | StringNewType(String), |
| 22 | /// A struct-like enum variant which contains |
| 23 | /// some floats |
| 24 | StructVariant { |
| 25 | /// The floats themselves |
| 26 | floats: Vec<f32>, |
| 27 | }, |
| 28 | } |
| 29 | |
| 30 | fn main() { |
| 31 | let schema = schema_for!(MyStruct); |
| 32 | println!("{}", serde_json::to_string_pretty(&schema).unwrap()); |
| 33 | } |