1
0
Fork 0

guess which types are url by field name

This commit is contained in:
Cyborus 2024-01-16 18:55:19 -05:00
parent 53922bc465
commit 61e24b800d
No known key found for this signature in database

View file

@ -709,12 +709,19 @@ fn create_struct_for_definition(
for (prop_name, prop_schema) in properties { for (prop_name, prop_schema) in properties {
let prop_ty = schema_ref_type_name(spec, prop_schema)?; let prop_ty = schema_ref_type_name(spec, prop_schema)?;
let field_name = sanitize_ident(prop_name); let field_name = sanitize_ident(prop_name);
let field_ty = match (!required.contains(prop_name), prop_ty == name) { let mut field_ty = prop_ty.clone();
(false, false) => prop_ty, if field_name.ends_with("url") && field_ty == "String" {
(false, true) => format!("Box<{prop_ty}>"), field_ty = "url::Url".into()
(true, false) => format!("Option<{prop_ty}>"), }
(true, true) => format!("Option<Box<{prop_ty}>>"), if field_ty == name {
}; field_ty = format!("Box<{field_ty}>")
}
if !required.contains(prop_name) {
field_ty = format!("Option<{field_ty}>")
}
if field_ty == "Option<url::Url>" {
fields.push_str("#[serde(deserialize_with = \"crate::none_if_blank_url\")]\n");
}
if &field_name != prop_name { if &field_name != prop_name {
fields.push_str("#[serde(rename = \""); fields.push_str("#[serde(rename = \"");
fields.push_str(prop_name); fields.push_str(prop_name);