Skip to content

Commit

Permalink
Handle odd cases where schema is inaccurate (#24)
Browse files Browse the repository at this point in the history
* Handle odd cases where schema is inaccurate

---------

Co-authored-by: ByteOtter <[email protected]>
  • Loading branch information
marv7000 and ByteOtter authored Feb 26, 2024
1 parent 28d6d2e commit 67c66f9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,23 @@ pub fn type_to_string(ty: &ReferenceOr<Schema>) -> 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<std::collections::HashMap<String, serde_json::Value>>".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 {
Expand Down

0 comments on commit 67c66f9

Please sign in to comment.