| 1 | use craterust-analyzer cargo schemars 1.2.2 crate/::preluderust-analyzer cargo schemars 1.2.2 prelude/::*; |
| 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:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 4 | struct UnitStructrust-analyzer cargo schemars 1.2.2 structs/UnitStruct#; |
| 5 | |
| 6 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7 | fn unitrust-analyzer cargo schemars 1.2.2 structs/unit().() { |
| 8 | testrust-analyzer cargo schemars 1.2.2 test!!(UnitStructrust-analyzer cargo schemars 1.2.2 structs/UnitStruct#) |
| 9 | .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().() |
| 10 | .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().() |
| 11 | .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().()); |
| 12 | } |
| 13 | |
| 14 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 15 | struct NormalStructrust-analyzer cargo schemars 1.2.2 structs/NormalStruct# { |
| 16 | foorust-analyzer cargo schemars 1.2.2 structs/NormalStruct#foo.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 17 | barrust-analyzer cargo schemars 1.2.2 structs/NormalStruct#bar.: bool, |
| 18 | } |
| 19 | |
| 20 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 21 | fn normalrust-analyzer cargo schemars 1.2.2 structs/normal().() { |
| 22 | testrust-analyzer cargo schemars 1.2.2 test!!(NormalStructrust-analyzer cargo schemars 1.2.2 structs/NormalStruct#) |
| 23 | .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().() |
| 24 | .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().() |
| 25 | .assert_allows_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_de_roundtrip().([jsonrust-analyzer cargo serde_json 1.0.151 macros/json!!({ |
| 26 | "foo": "", |
| 27 | "bar": true, |
| 28 | "unknown": 123 |
| 29 | })]) |
| 30 | .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().()); |
| 31 | } |
| 32 | |
| 33 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 34 | struct NewTyperust-analyzer cargo schemars 1.2.2 structs/NewType#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#); |
| 35 | |
| 36 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 37 | fn newtyperust-analyzer cargo schemars 1.2.2 structs/newtype().() { |
| 38 | testrust-analyzer cargo schemars 1.2.2 test!!(NewTyperust-analyzer cargo schemars 1.2.2 structs/NewType#) |
| 39 | .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().() |
| 40 | .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().() |
| 41 | .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().()); |
| 42 | } |
| 43 | |
| 44 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 45 | struct TupleStructrust-analyzer cargo schemars 1.2.2 structs/TupleStruct#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, bool); |
| 46 | |
| 47 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 48 | fn tuplerust-analyzer cargo schemars 1.2.2 structs/tuple().() { |
| 49 | testrust-analyzer cargo schemars 1.2.2 test!!(TupleStructrust-analyzer cargo schemars 1.2.2 structs/TupleStruct#) |
| 50 | .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().() |
| 51 | .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().() |
| 52 | .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().()); |
| 53 | } |
| 54 | |
| 55 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 56 | #[serde(rename_all = "camelCase")] |
| 57 | struct RenamedFieldsrust-analyzer cargo schemars 1.2.2 structs/RenamedFields# { |
| 58 | camel_caserust-analyzer cargo schemars 1.2.2 structs/RenamedFields#camel_case.: i32, |
| 59 | #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(rename = "new_name")] |
| 60 | old_namerust-analyzer cargo schemars 1.2.2 structs/RenamedFields#old_name.: i32, |
| 61 | } |
| 62 | |
| 63 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 64 | fn renamed_fieldsrust-analyzer cargo schemars 1.2.2 structs/renamed_fields().() { |
| 65 | testrust-analyzer cargo schemars 1.2.2 test!!(RenamedFieldsrust-analyzer cargo schemars 1.2.2 structs/RenamedFields#) |
| 66 | .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().() |
| 67 | .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().() |
| 68 | .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().()); |
| 69 | } |
| 70 | |
| 71 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 72 | #[serde(deny_unknown_fields)] |
| 73 | struct DenyUnknownFieldsrust-analyzer cargo schemars 1.2.2 structs/DenyUnknownFields# { |
| 74 | foorust-analyzer cargo schemars 1.2.2 structs/DenyUnknownFields#foo.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 75 | barrust-analyzer cargo schemars 1.2.2 structs/DenyUnknownFields#bar.: bool, |
| 76 | } |
| 77 | |
| 78 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 79 | fn deny_unknown_fieldsrust-analyzer cargo schemars 1.2.2 structs/deny_unknown_fields().() { |
| 80 | testrust-analyzer cargo schemars 1.2.2 test!!(DenyUnknownFieldsrust-analyzer cargo schemars 1.2.2 structs/DenyUnknownFields#) |
| 81 | .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().() |
| 82 | .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().() |
| 83 | .assert_rejects_derust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_rejects_de().([jsonrust-analyzer cargo serde_json 1.0.151 macros/json!!({ |
| 84 | "foo": "", |
| 85 | "bar": true, |
| 86 | "unknown": 123 |
| 87 | })]) |
| 88 | .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().()); |
| 89 | } |
| 90 | |
| 91 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 92 | #[schemars(example = PropertyOrderrust-analyzer cargo schemars 1.2.2 structs/PropertyOrder#::defaultrust-analyzer cargo schemars 1.2.2 structs/impl#[PropertyOrder][Default]default().(), extend("x-custom" = PropertyOrderrust-analyzer cargo schemars 1.2.2 structs/PropertyOrder#::defaultrust-analyzer cargo schemars 1.2.2 structs/impl#[PropertyOrder][Default]default().()))] |
| 93 | struct PropertyOrderrust-analyzer cargo schemars 1.2.2 structs/PropertyOrder# { |
| 94 | #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(rename = "$defs")] |
| 95 | pub defsrust-analyzer cargo schemars 1.2.2 structs/PropertyOrder#defs.: UnitStructrust-analyzer cargo schemars 1.2.2 structs/UnitStruct#, |
| 96 | pub examplesrust-analyzer cargo schemars 1.2.2 structs/PropertyOrder#examples.: UnitStructrust-analyzer cargo schemars 1.2.2 structs/UnitStruct#, |
| 97 | pub propertiesrust-analyzer cargo schemars 1.2.2 structs/PropertyOrder#properties.: UnitStructrust-analyzer cargo schemars 1.2.2 structs/UnitStruct#, |
| 98 | pub requiredrust-analyzer cargo schemars 1.2.2 structs/PropertyOrder#required.: UnitStructrust-analyzer cargo schemars 1.2.2 structs/UnitStruct#, |
| 99 | #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(rename = "$schema")] |
| 100 | pub schemarust-analyzer cargo schemars 1.2.2 structs/PropertyOrder#schema.: UnitStructrust-analyzer cargo schemars 1.2.2 structs/UnitStruct#, |
| 101 | pub titlerust-analyzer cargo schemars 1.2.2 structs/PropertyOrder#title.: UnitStructrust-analyzer cargo schemars 1.2.2 structs/UnitStruct#, |
| 102 | pub r#typerust-analyzer cargo schemars 1.2.2 structs/PropertyOrder#`r#type`.: UnitStructrust-analyzer cargo schemars 1.2.2 structs/UnitStruct#, |
| 103 | #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(rename = "x-custom")] |
| 104 | pub x_customrust-analyzer cargo schemars 1.2.2 structs/PropertyOrder#x_custom.: UnitStructrust-analyzer cargo schemars 1.2.2 structs/UnitStruct#, |
| 105 | } |
| 106 | |
| 107 | #[cfg_attr(not(feature = "preserve_order"), ignore)] |
| 108 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 109 | fn property_orderrust-analyzer cargo schemars 1.2.2 structs/property_order().() { |
| 110 | testrust-analyzer cargo schemars 1.2.2 test!!(PropertyOrderrust-analyzer cargo schemars 1.2.2 structs/PropertyOrder#).assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().().customrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]custom().(|schema, _| { |
| 111 | fn get_property_keysrust-analyzer cargo schemars 1.2.2 structs/get_property_keys().(value: &Valuerust-analyzer cargo serde_json 1.0.151 value/Value#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> { |
| 112 | value |
| 113 | .as_objectrust-analyzer cargo serde_json 1.0.151 value/impl#[Value]as_object().() |
| 114 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("expected value to be an object") |
| 115 | .keysrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]keys().() |
| 116 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().) |
| 117 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 118 | } |
| 119 | |
| 120 | let value = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_valuerust-analyzer cargo serde_json 1.0.151 value/to_value().(schema).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 121 | |
| 122 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!( |
| 123 | get_property_keysrust-analyzer cargo schemars 1.2.2 structs/get_property_keys().(&value).as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().(), |
| 124 | // order of `examples`, `required` and `x-custom` is unspecified |
| 125 | &["$schema", "title", "type", "properties", .., "$defs"] |
| 126 | )); |
| 127 | |
| 128 | let field_order = &[ |
| 129 | "$defs", |
| 130 | "examples", |
| 131 | "properties", |
| 132 | "required", |
| 133 | "$schema", |
| 134 | "title", |
| 135 | "type", |
| 136 | "x-custom", |
| 137 | ]; |
| 138 | |
| 139 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 140 | get_property_keysrust-analyzer cargo schemars 1.2.2 structs/get_property_keys().(&value[rust-analyzer cargo serde_json 1.0.151 value/index/impl#[Value][`Index<I>`]index()."properties"]rust-analyzer cargo serde_json 1.0.151 value/index/impl#[Value][`Index<I>`]index().).as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().(), |
| 141 | field_order, |
| 142 | ); |
| 143 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 144 | get_property_keysrust-analyzer cargo schemars 1.2.2 structs/get_property_keys().(&value[rust-analyzer cargo serde_json 1.0.151 value/index/impl#[Value][`Index<I>`]index()."examples"]rust-analyzer cargo serde_json 1.0.151 value/index/impl#[Value][`Index<I>`]index().[rust-analyzer cargo serde_json 1.0.151 value/index/impl#[Value][`Index<I>`]index().0]rust-analyzer cargo serde_json 1.0.151 value/index/impl#[Value][`Index<I>`]index().).as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().(), |
| 145 | field_order, |
| 146 | ); |
| 147 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 148 | get_property_keysrust-analyzer cargo schemars 1.2.2 structs/get_property_keys().(&value[rust-analyzer cargo serde_json 1.0.151 value/index/impl#[Value][`Index<I>`]index()."x-custom"]rust-analyzer cargo serde_json 1.0.151 value/index/impl#[Value][`Index<I>`]index().).as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().(), |
| 149 | field_order, |
| 150 | ); |
| 151 | }); |
| 152 | } |