| 1 | use schemarsrust-analyzer cargo schemars 1.2.2 crate/::{schema_forrust-analyzer cargo schemars 1.2.2 macros/schema_for!, JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#}; |
| 2 | |
| 3 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:)] |
| 4 | pub struct MyStructrust-analyzer cargo schemars 1.2.2 MyStruct# { |
| 5 | #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(range(min = 1, max = 10))] |
| 6 | pub my_intrust-analyzer cargo schemars 1.2.2 MyStruct#my_int.: i32, |
| 7 | pub my_boolrust-analyzer cargo schemars 1.2.2 MyStruct#my_bool.: bool, |
| 8 | #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(required)] |
| 9 | pub my_nullable_enumrust-analyzer cargo schemars 1.2.2 MyStruct#my_nullable_enum.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<MyEnumrust-analyzer cargo schemars 1.2.2 MyEnum#>, |
| 10 | } |
| 11 | |
| 12 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:)] |
| 13 | pub enum MyEnumrust-analyzer cargo schemars 1.2.2 MyEnum# { |
| 14 | StringNewTyperust-analyzer cargo schemars 1.2.2 MyEnum#StringNewType#(#[validate(email)] Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 15 | StructVariantrust-analyzer cargo schemars 1.2.2 MyEnum#StructVariant# { |
| 16 | #[validate(length(min = 1, max = 100))] |
| 17 | floatsrust-analyzer cargo schemars 1.2.2 MyEnum#StructVariant#floats.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<f32>, |
| 18 | }, |
| 19 | } |
| 20 | |
| 21 | fn mainrust-analyzer cargo schemars 1.2.2 main().() { |
| 22 | let schema = schema_forrust-analyzer cargo schemars 1.2.2 macros/schema_for!!(MyStructrust-analyzer cargo schemars 1.2.2 MyStruct#); |
| 23 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}", serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_string_prettyrust-analyzer cargo serde_json 1.0.151 ser/to_string_pretty().(&schema).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 24 | } |