| 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#, Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#}; |
| 2 | use serderust-analyzer cargo serde 1.0.229 crate/::{Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#, Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#}; |
| 3 | |
| 4 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:)] |
| 5 | #[schemars(rename_all = "camelCase", deny_unknown_fields, extend("x-customProperty" = "example"))] |
| 6 | pub struct MyStructrust-analyzer cargo schemars 1.2.2 MyStruct# { |
| 7 | #[serderust-analyzer cargo serde_derive 1.0.229 serde:(rename = "thisIsOverridden")] |
| 8 | #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(rename = "myNumber", range(min = 1, max = 10), transform = remove_formatrust-analyzer cargo schemars 1.2.2 remove_format().)] |
| 9 | pub my_intrust-analyzer cargo schemars 1.2.2 MyStruct#my_int.: i32, |
| 10 | pub my_boolrust-analyzer cargo schemars 1.2.2 MyStruct#my_bool.: bool, |
| 11 | #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(default)] |
| 12 | 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#>, |
| 13 | #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(inner(regex(pattern = "^x$")))] |
| 14 | pub my_vec_strrust-analyzer cargo schemars 1.2.2 MyStruct#my_vec_str.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 15 | } |
| 16 | |
| 17 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:)] |
| 18 | #[schemars(untagged)] |
| 19 | pub enum MyEnumrust-analyzer cargo schemars 1.2.2 MyEnum# { |
| 20 | StringNewTyperust-analyzer cargo schemars 1.2.2 MyEnum#StringNewType#(#[schemars(email)] Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 21 | StructVariantrust-analyzer cargo schemars 1.2.2 MyEnum#StructVariant# { |
| 22 | #[schemars(length(min = 1, max = 100))] |
| 23 | 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>, |
| 24 | }, |
| 25 | } |
| 26 | |
| 27 | fn remove_formatrust-analyzer cargo schemars 1.2.2 remove_format().(schema: &mut Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#) { |
| 28 | schema.removerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]remove().("format"); |
| 29 | } |
| 30 | |
| 31 | fn mainrust-analyzer cargo schemars 1.2.2 main().() { |
| 32 | let schema = schema_forrust-analyzer cargo schemars 1.2.2 macros/schema_for!!(MyStructrust-analyzer cargo schemars 1.2.2 MyStruct#); |
| 33 | 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().()); |
| 34 | } |