diff --git a/Cargo.lock b/Cargo.lock index 38839e3..7afc738 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2316,7 +2316,7 @@ dependencies = [ [[package]] name = "torn-api-codegen" -version = "0.7.4" +version = "0.7.5" dependencies = [ "heck", "indexmap", diff --git a/torn-api-codegen/Cargo.toml b/torn-api-codegen/Cargo.toml index 038e453..2ec7ec7 100644 --- a/torn-api-codegen/Cargo.toml +++ b/torn-api-codegen/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "torn-api-codegen" authors = ["Pyrit [2111649]"] -version = "0.7.4" +version = "0.7.5" edition = "2021" description = "Contains the v2 torn API model descriptions and codegen for the bindings" license = { workspace = true } diff --git a/torn-api-codegen/src/model/path.rs b/torn-api-codegen/src/model/path.rs index 8360baa..66df454 100644 --- a/torn-api-codegen/src/model/path.rs +++ b/torn-api-codegen/src/model/path.rs @@ -258,12 +258,14 @@ impl Path { } else { let ty = if param.required { convert_field.push(quote! { - .chain(std::iter::once(&self.#name).map(|v| (#query_val, v.to_string()))) + parameters.push((#query_val, self.#name.to_string())); }); ty } else { convert_field.push(quote! { - .chain(self.#name.as_ref().into_iter().map(|v| (#query_val, v.to_string()))) + if let Some(value) = &self.#name { + parameters.push((#query_val, value.to_string())); + } }); quote! { Option<#ty>} }; @@ -295,8 +297,8 @@ impl Path { let mut path_fmt_str = String::new(); for seg in &self.segments { match seg { - PathSegment::Constant(val) => _ = write!(path_fmt_str, "/{}", val), - PathSegment::Parameter { name } => _ = write!(path_fmt_str, "/{{{}}}", name), + PathSegment::Constant(val) => _ = write!(path_fmt_str, "/{val}"), + PathSegment::Parameter { name } => _ = write!(path_fmt_str, "/{{{name}}}"), } } @@ -324,14 +326,15 @@ impl Path { type Response = #response_ty; fn into_request(self) -> (Self::Discriminant, crate::request::ApiRequest) { let path = format!(#path_fmt_str, #(#fmt_val),*); + let mut parameters = Vec::new(); + #(#convert_field)* + #[allow(unused_parens)] ( (#(#discriminant_val),*), crate::request::ApiRequest { path, - parameters: std::iter::empty() - #(#convert_field)* - .collect(), + parameters, } ) }