feat(codegen): decreased complexity of generated code
This commit is contained in:
parent
3d80414441
commit
12cfcf7f11
3 changed files with 12 additions and 9 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -2316,7 +2316,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "torn-api-codegen"
|
name = "torn-api-codegen"
|
||||||
version = "0.7.4"
|
version = "0.7.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "torn-api-codegen"
|
name = "torn-api-codegen"
|
||||||
authors = ["Pyrit [2111649]"]
|
authors = ["Pyrit [2111649]"]
|
||||||
version = "0.7.4"
|
version = "0.7.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Contains the v2 torn API model descriptions and codegen for the bindings"
|
description = "Contains the v2 torn API model descriptions and codegen for the bindings"
|
||||||
license = { workspace = true }
|
license = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -258,12 +258,14 @@ impl Path {
|
||||||
} else {
|
} else {
|
||||||
let ty = if param.required {
|
let ty = if param.required {
|
||||||
convert_field.push(quote! {
|
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
|
ty
|
||||||
} else {
|
} else {
|
||||||
convert_field.push(quote! {
|
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>}
|
quote! { Option<#ty>}
|
||||||
};
|
};
|
||||||
|
|
@ -295,8 +297,8 @@ impl Path {
|
||||||
let mut path_fmt_str = String::new();
|
let mut path_fmt_str = String::new();
|
||||||
for seg in &self.segments {
|
for seg in &self.segments {
|
||||||
match seg {
|
match seg {
|
||||||
PathSegment::Constant(val) => _ = write!(path_fmt_str, "/{}", val),
|
PathSegment::Constant(val) => _ = write!(path_fmt_str, "/{val}"),
|
||||||
PathSegment::Parameter { name } => _ = write!(path_fmt_str, "/{{{}}}", name),
|
PathSegment::Parameter { name } => _ = write!(path_fmt_str, "/{{{name}}}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -324,14 +326,15 @@ impl Path {
|
||||||
type Response = #response_ty;
|
type Response = #response_ty;
|
||||||
fn into_request(self) -> (Self::Discriminant, crate::request::ApiRequest) {
|
fn into_request(self) -> (Self::Discriminant, crate::request::ApiRequest) {
|
||||||
let path = format!(#path_fmt_str, #(#fmt_val),*);
|
let path = format!(#path_fmt_str, #(#fmt_val),*);
|
||||||
|
let mut parameters = Vec::new();
|
||||||
|
#(#convert_field)*
|
||||||
|
|
||||||
#[allow(unused_parens)]
|
#[allow(unused_parens)]
|
||||||
(
|
(
|
||||||
(#(#discriminant_val),*),
|
(#(#discriminant_val),*),
|
||||||
crate::request::ApiRequest {
|
crate::request::ApiRequest {
|
||||||
path,
|
path,
|
||||||
parameters: std::iter::empty()
|
parameters,
|
||||||
#(#convert_field)*
|
|
||||||
.collect(),
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue