diff options
author | Cyborus <cyborus@cyborus.xyz> | 2024-01-16 23:27:03 +0100 |
---|---|---|
committer | Cyborus <cyborus@cyborus.xyz> | 2024-01-16 23:27:03 +0100 |
commit | 41c710281dd61ddacac759077de77ab826be1727 (patch) | |
tree | 77d62c44baa4a5dec82461bdd6657336ec9274dc | |
parent | impl on `crate::Forgejo` instead of `Forgejo` (diff) | |
download | forgejo-api-41c710281dd61ddacac759077de77ab826be1727.tar.xz forgejo-api-41c710281dd61ddacac759077de77ab826be1727.zip |
sanitize body arg
-rw-r--r-- | generator/src/main.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/generator/src/main.rs b/generator/src/main.rs index e735d7b..184e65d 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -421,6 +421,7 @@ fn create_method_request( MaybeRef::Value { value } => value, MaybeRef::Ref { _ref } => eyre::bail!("todo: add deref parameters"), }; + let name = sanitize_ident(param.name.to_snake_case()); match param._in { ParameterIn::Path => (/* do nothing */), ParameterIn::Query => has_query = true, @@ -430,16 +431,16 @@ fn create_method_request( eyre::bail!("cannot have more than one body parameter"); } if param_is_string(spec, param)? { - body_method = format!(".body({})", param.name); + body_method = format!(".body({name})"); } else { - body_method = format!(".json({})?", param.name); + body_method = format!(".json({name})?"); } } ParameterIn::FormData => { if !body_method.is_empty() { eyre::bail!("cannot have more than one body parameter"); } - body_method = format!(".multipart(reqwest::multipart::Form::new().part(\"attachment\", reqwest::multipart::Part::bytes({}).file_name(\"file\").mime_str(\"*/*\").unwrap()))", param.name); + body_method = format!(".multipart(reqwest::multipart::Form::new().part(\"attachment\", reqwest::multipart::Part::bytes({name}).file_name(\"file\").mime_str(\"*/*\").unwrap()))"); } } } |