| 1 | use schemars::{generate::SchemaSettings, JsonSchema}; |
| 2 | |
| 3 | #[derive(JsonSchema)] |
| 4 | pub struct MyStruct { |
| 5 | pub my_int: i32, |
| 6 | pub my_bool: bool, |
| 7 | pub my_nullable_enum: Option<MyEnum>, |
| 8 | } |
| 9 | |
| 10 | #[derive(JsonSchema)] |
| 11 | pub enum MyEnum { |
| 12 | StringNewType(String), |
| 13 | StructVariant { floats: Vec<f32> }, |
| 14 | } |
| 15 | |
| 16 | fn main() { |
| 17 | let settings = SchemaSettings::draft07().with(|s| { |
| 18 | s.meta_schema = None; |
| 19 | s.inline_subschemas = true; |
| 20 | }); |
| 21 | let generator = settings.into_generator(); |
| 22 | let schema = generator.into_root_schema_for::<MyStruct>(); |
| 23 | println!("{}", serde_json::to_string_pretty(&schema).unwrap()); |
| 24 | } |