diff options
author | Cyborus <cyborus@cyborus.xyz> | 2024-01-17 00:55:19 +0100 |
---|---|---|
committer | Cyborus <cyborus@cyborus.xyz> | 2024-01-17 00:55:19 +0100 |
commit | 61e24b800d4107bf8ec4fb3053620a1a64652013 (patch) | |
tree | 23bf38b71bf945d6b531666927a9710f45ab88f7 /generator | |
parent | make `*Query::to_string` take `self` (diff) | |
download | forgejo-api-61e24b800d4107bf8ec4fb3053620a1a64652013.tar.xz forgejo-api-61e24b800d4107bf8ec4fb3053620a1a64652013.zip |
guess which types are url by field name
Diffstat (limited to 'generator')
-rw-r--r-- | generator/src/main.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/generator/src/main.rs b/generator/src/main.rs index 1b17240..b0da534 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -709,12 +709,19 @@ fn create_struct_for_definition( for (prop_name, prop_schema) in properties { let prop_ty = schema_ref_type_name(spec, prop_schema)?; let field_name = sanitize_ident(prop_name); - let field_ty = match (!required.contains(prop_name), prop_ty == name) { - (false, false) => prop_ty, - (false, true) => format!("Box<{prop_ty}>"), - (true, false) => format!("Option<{prop_ty}>"), - (true, true) => format!("Option<Box<{prop_ty}>>"), - }; + let mut field_ty = prop_ty.clone(); + if field_name.ends_with("url") && field_ty == "String" { + field_ty = "url::Url".into() + } + 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 { fields.push_str("#[serde(rename = \""); fields.push_str(prop_name); |