From 68ed9ededd435a3ec0244dd42d3b0f97abc22cb4 Mon Sep 17 00:00:00 2001 From: Marvin Friedrich Date: Mon, 26 Feb 2024 14:38:53 +0100 Subject: [PATCH 1/2] Handle odd cases where schema is inaccurate --- src/bindgen.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 5ffad8a..0cfff4f 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -154,18 +154,21 @@ pub fn type_to_string(ty: &ReferenceOr) -> String { } None => "i64", }; - return int_size.to_owned(); + int_size.to_owned() } // JSON object, but Rust has no easy way to support this, so just ask for a string. - Type::Object(_) => "String".to_owned(), + Type::Object(_) => "Option>".to_owned(), Type::Boolean(_) => "bool".to_owned(), Type::Array(x) => { let items = x.items.as_ref().unwrap().clone().unbox(); format!("Vec<{}>", type_to_string(&items)) } }, + SchemaKind::AllOf { all_of } => { + format!("Option<{}>", type_to_string(&all_of[0].clone())) + }, // Very likely a JSON object. - _ => "String".to_owned(), + _ => "serde_json::Value".to_owned(), }; // If property is nullable, we treat it as an optional argument. if item.schema_data.nullable { From d81244708413e3477879d976431a9e31a9928674 Mon Sep 17 00:00:00 2001 From: ByteOtter Date: Mon, 26 Feb 2024 14:41:04 +0100 Subject: [PATCH 2/2] format code --- src/bindgen.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 0cfff4f..209a1c2 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -157,7 +157,9 @@ pub fn type_to_string(ty: &ReferenceOr) -> String { int_size.to_owned() } // JSON object, but Rust has no easy way to support this, so just ask for a string. - Type::Object(_) => "Option>".to_owned(), + Type::Object(_) => { + "Option>".to_owned() + } Type::Boolean(_) => "bool".to_owned(), Type::Array(x) => { let items = x.items.as_ref().unwrap().clone().unbox(); @@ -166,7 +168,7 @@ pub fn type_to_string(ty: &ReferenceOr) -> String { }, SchemaKind::AllOf { all_of } => { format!("Option<{}>", type_to_string(&all_of[0].clone())) - }, + } // Very likely a JSON object. _ => "serde_json::Value".to_owned(), };