Skip to content

Commit cdd7ea4

Browse files
committed
Fixed schema again
1 parent ecb085d commit cdd7ea4

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

src/frontend/serialization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ mod tests {
154154
]))
155155
.unwrap(),
156156
),
157-
"{\"Dictionary\":{\"max_depth\":32,\"kvs\":{\"\":\"baz\",\"\\u0000\":\"\",\" hi\":false,\"!@£$%^&&*()\":\"\",\"foo\":{\"Int\":\"123\"},\"🥳\":\"party time!\"}}}",
157+
"{\"max_depth\":32,\"kvs\":{\"\":\"baz\",\"\\u0000\":\"\",\" hi\":false,\"!@£$%^&&*()\":\"\",\"foo\":{\"Int\":\"123\"},\"🥳\":\"party time!\"}}",
158158
),
159159
(
160160
TypedValue::Set(Set::new(params.max_depth_mt_containers, HashSet::from(["foo".into(), "bar".into()])).unwrap()),
161-
"{\"Set\":{\"max_depth\":32,\"set\":[\"bar\",\"foo\"]}}",
161+
"{\"max_depth\":32,\"set\":[\"bar\",\"foo\"]}",
162162
),
163163
];
164164

src/middleware/mod.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ pub enum TypedValue {
5353
// 53-bit precision for integers, integers are represented as tagged
5454
// strings, with a custom serializer and deserializer.
5555
// TAGGED TYPES:
56-
Set(Set),
57-
Dictionary(Dictionary),
5856
Int(
5957
#[serde(serialize_with = "serialize_i64", deserialize_with = "deserialize_i64")]
6058
// #[schemars(with = "String", regex(pattern = r"^\d+$"))]
@@ -67,6 +65,10 @@ pub enum TypedValue {
6765
PodId(PodId),
6866
// UNTAGGED TYPES:
6967
#[serde(untagged)]
68+
Set(Set),
69+
#[serde(untagged)]
70+
Dictionary(Dictionary),
71+
#[serde(untagged)]
7072
Array(Array),
7173
#[serde(untagged)]
7274
String(String),
@@ -230,18 +232,6 @@ impl JsonSchema for TypedValue {
230232
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
231233
use schemars::schema::{InstanceType, Schema, SchemaObject, SingleOrVec};
232234

233-
let dictionary_schema = schemars::schema::SchemaObject {
234-
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Object))),
235-
object: Some(Box::new(schemars::schema::ObjectValidation {
236-
properties: [("Dictionary".to_string(), gen.subschema_for::<Dictionary>())]
237-
.into_iter()
238-
.collect(),
239-
required: ["Dictionary".to_string()].into_iter().collect(),
240-
..Default::default()
241-
})),
242-
..Default::default()
243-
};
244-
245235
// Int is serialized/deserialized as a tagged string
246236
let int_schema = schemars::schema::SchemaObject {
247237
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Object))),
@@ -293,17 +283,18 @@ impl JsonSchema for TypedValue {
293283
// This is the part that Schemars can't generate automatically:
294284
let untagged_array_schema = gen.subschema_for::<Array>();
295285
let untagged_set_schema = gen.subschema_for::<Set>();
286+
let untagged_dictionary_schema = gen.subschema_for::<Dictionary>();
296287
let untagged_string_schema = gen.subschema_for::<String>();
297288
let untagged_bool_schema = gen.subschema_for::<bool>();
298289

299290
Schema::Object(SchemaObject {
300291
subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
301292
any_of: Some(vec![
302-
Schema::Object(dictionary_schema),
303293
Schema::Object(int_schema),
304294
Schema::Object(raw_schema),
305295
Schema::Object(public_key_schema),
306296
untagged_array_schema,
297+
untagged_dictionary_schema,
307298
untagged_string_schema,
308299
untagged_set_schema,
309300
untagged_bool_schema,

0 commit comments

Comments
 (0)