Debian Codegraph @

src/json_schema_impls/maps.rs

raw symbols SCIP
1 use craterust-analyzer cargo schemars 1.2.2 crate/::_alloc_preluderust-analyzer cargo schemars 1.2.2 _alloc_prelude/::*;
2 use craterust-analyzer cargo schemars 1.2.2 crate/::{json_schemarust-analyzer cargo schemars 1.2.2 macros/json_schema!, JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#, Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#, SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#};
3 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
4 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::collectionsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/::{BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#, BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#};
5 use serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::{Maprust-analyzer cargo serde_json 1.0.151 map/Map#, Valuerust-analyzer cargo serde_json 1.0.151 value/Value#};
6
7 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
8 enum IntegerSupportrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport# {
9 Nonerust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#None#,
10 Unsignedrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#Unsigned#,
11 Signedrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#Signed#,
12 }
13
14 impl<K, V> JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema# for BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<K, V>
15 where
16 K: JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#,
17 V: JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#,
18 {
19 inline_schemarust-analyzer cargo schemars 1.2.2 json_schema_impls/inline_schema!!();
20
21 fn schema_namerust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/impl#[`BTreeMap<K, V>`][JsonSchema]schema_name().() -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str> {
22 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(if K::schema_idrust-analyzer cargo schemars 1.2.2 JsonSchema#schema_id().() rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'a, B>`][`PartialEq<Cow<'b, C>>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'a, B>`][`PartialEq<Cow<'b, C>>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'a, B>`][`PartialEq<Cow<'b, C>>`]eq().<str>::schema_idrust-analyzer cargo schemars 1.2.2 JsonSchema#schema_id().() {
23 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Map_of_{}", V::schema_namerust-analyzer cargo schemars 1.2.2 JsonSchema#schema_name().())
24 } else {
25 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Map_from_{}_to_{}", K::schema_namerust-analyzer cargo schemars 1.2.2 JsonSchema#schema_name().(), V::schema_namerust-analyzer cargo schemars 1.2.2 JsonSchema#schema_name().())
26 })
27 }
28
29 fn schema_idrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/impl#[`BTreeMap<K, V>`][JsonSchema]schema_id().() -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str> {
30 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(if K::schema_idrust-analyzer cargo schemars 1.2.2 JsonSchema#schema_id().() rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'a, B>`][`PartialEq<Cow<'b, C>>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'a, B>`][`PartialEq<Cow<'b, C>>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'a, B>`][`PartialEq<Cow<'b, C>>`]eq().<str>::schema_idrust-analyzer cargo schemars 1.2.2 JsonSchema#schema_id().() {
31 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Map<{}>", V::schema_idrust-analyzer cargo schemars 1.2.2 JsonSchema#schema_id().())
32 } else {
33 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Map<{}, {}>", K::schema_idrust-analyzer cargo schemars 1.2.2 JsonSchema#schema_id().(), V::schema_idrust-analyzer cargo schemars 1.2.2 JsonSchema#schema_id().())
34 })
35 }
36
37 fn json_schemarust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/impl#[`BTreeMap<K, V>`][JsonSchema]json_schema().(generator: &mut SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#) -> Schemarust-analyzer cargo schemars 1.2.2 schema/Schema# {
38 let key_schema = K::json_schemarust-analyzer cargo schemars 1.2.2 JsonSchema#json_schema().(generator);
39 let value_schema = generator.subschema_forrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]subschema_for().::<V>();
40
41 let mut map_schema = json_schemarust-analyzer cargo schemars 1.2.2 macros/json_schema!!({
42 "type": "object",
43 });
44
45 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut options) = key_schema
46 .getrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]get().("anyOf")
47 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::as_arrayrust-analyzer cargo serde_json 1.0.151 value/impl#[Value]as_array().)
48 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|a| a.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::as_objectrust-analyzer cargo serde_json 1.0.151 value/impl#[Value]as_object().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>>())
49 .or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or_else().(|| Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![key_schema.as_objectrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]as_object().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().]))
50 else {
51 return json_schemarust-analyzer cargo schemars 1.2.2 macros/json_schema!!({
52 "additionalProperties": value_schema,
53 "type": "object",
54 });
55 };
56
57 // Handle refs
58 let prefix = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("#{}/", generator.definitions_path_strippedrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]definitions_path_stripped().());
59 for option in &mut options {
60 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(d) = option
61 .getrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]get().("$ref")
62 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::as_strrust-analyzer cargo serde_json 1.0.151 value/impl#[Value]as_str().)
63 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|r| r.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().(&prefix))
64 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|r| generator.definitionsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]definitions().().getrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]get().(r))
65 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::as_objectrust-analyzer cargo serde_json 1.0.151 value/impl#[Value]as_object().)
66 {
67 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().option = d;
68 }
69 }
70
71 let mut additional_properties = false;
72 let mut support_integers = IntegerSupportrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#::Nonerust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#None#;
73 let mut patterns = BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T>`]new().();
74 let mut properties = BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T>`]new().();
75 for option in options {
76 let key_pattern = option.getrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]get().("pattern").and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::as_strrust-analyzer cargo serde_json 1.0.151 value/impl#[Value]as_str().);
77 let key_enum = option
78 .getrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]get().("enum")
79 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::as_arrayrust-analyzer cargo serde_json 1.0.151 value/impl#[Value]as_array().)
80 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|a| a.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::as_strrust-analyzer cargo serde_json 1.0.151 value/impl#[Value]as_str().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>>());
81 let key_type = option.getrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]get().("type").and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::as_strrust-analyzer cargo serde_json 1.0.151 value/impl#[Value]as_str().);
82 let key_minimum = option.getrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]get().("minimum").and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::as_u64rust-analyzer cargo serde_json 1.0.151 value/impl#[Value]as_u64().);
83
84 match (key_pattern, key_enum, key_type) {
85 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pattern), _, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("string")) => {
86 patterns.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]insert().(pattern);
87 }
88 (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(enum_values), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("string")) => {
89 for value in enum_values {
90 properties.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]insert().(value);
91 }
92 }
93 (_, _, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("integer")) if key_minimum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0) => {
94 support_integers = support_integers.maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(IntegerSupportrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#::Unsignedrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#Unsigned#);
95 }
96 (_, _, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("integer")) => {
97 support_integers = support_integers.maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(IntegerSupportrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#::Signedrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#Signed#);
98 }
99 _ => {
100 additional_properties = true;
101 }
102 }
103 }
104
105 if additional_properties {
106 map_schema.insertrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]insert().(
107 "additionalProperties".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
108 value_schema.clonerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema][Clone]clone().().to_valuerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]to_value().(),
109 );
110 } else {
111 map_schema.insertrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]insert().("additionalProperties".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::Boolrust-analyzer cargo serde_json 1.0.151 value/Value#Bool#(false));
112 }
113
114 match support_integers {
115 IntegerSupportrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#::Nonerust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#None# => {}
116 IntegerSupportrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#::Unsignedrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#Unsigned# => {
117 patterns.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]insert().(r"^\d+$");
118 }
119 IntegerSupportrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#::Signedrust-analyzer cargo schemars 1.2.2 json_schema_impls/maps/IntegerSupport#Signed# => {
120 patterns.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]insert().(r"^-?\d+$");
121 }
122 }
123
124 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().patterns.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]is_empty().() {
125 let mut patterns_map = Maprust-analyzer cargo serde_json 1.0.151 map/Map#::newrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]new().();
126
127 for pattern in patterns {
128 patterns_map.insertrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]insert().(pattern.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), value_schema.clonerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema][Clone]clone().().to_valuerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]to_value().());
129 }
130
131 map_schema.insertrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]insert().("patternProperties".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::Objectrust-analyzer cargo serde_json 1.0.151 value/Value#Object#(patterns_map));
132 }
133
134 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().properties.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]is_empty().() {
135 let mut properties_map = Maprust-analyzer cargo serde_json 1.0.151 map/Map#::newrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]new().();
136
137 for property in properties {
138 properties_map.insertrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]insert().(property.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), value_schema.clonerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema][Clone]clone().().to_valuerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]to_value().());
139 }
140
141 map_schema.insertrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]insert().("properties".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::Objectrust-analyzer cargo serde_json 1.0.151 value/Value#Object#(properties_map));
142 }
143
144 map_schema
145 }
146 }
147
148 #[cfg(feature = "std")]
149 forward_implrust-analyzer cargo schemars 1.2.2 json_schema_impls/forward_impl!!((<K: JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#, V: JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#, H> JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema# for stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<K, V, H>) => BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<K, V>);