Skip to content

Commit

Permalink
simplify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
omid committed Apr 25, 2024
1 parent 0c858be commit 186d8b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
21 changes: 5 additions & 16 deletions examples/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,30 +435,19 @@ mod openapi {

output.extend(query_parameters.into_iter().flat_map(
|(query_parameter, query_parameter_name)| {
let stringify = match &query_parameter.schema {
Kind::Generic(v) => match v {
Generic::Array { .. } => r#" let v = v.join(",");"#,
_ => "",
},
_ => "",
let value = match &query_parameter.schema {
Kind::Generic(Generic::Array { .. }) => r#"v.join(",")"#,
_ => "v",
};
[
format!("if let Some(v) = {query_parameter_name} {{"),
stringify.to_string(),
format!(
r#" builder = builder.query(&[("{}", v)]);"#,
r#" builder = builder.query(&[("{}", {value})]);"#,
query_parameter.name
),
"}".into(),
]
.into_iter()
.filter_map(|line| {
if line.is_empty() {
None
} else {
Some(format!(" {line}"))
}
})
.map(|line| format!(" {line}"))
},
));

Expand Down
9 changes: 3 additions & 6 deletions src/rest/generated_rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5405,15 +5405,13 @@ impl<TS: KeycloakTokenSupplier> KeycloakAdmin<TS> {
builder = builder.query(&[("max", v)]);
}
if let Some(v) = operation_types {
let v = v.join(",");
builder = builder.query(&[("operationTypes", v)]);
builder = builder.query(&[("operationTypes", v.join(","))]);
}
if let Some(v) = resource_path {
builder = builder.query(&[("resourcePath", v)]);
}
if let Some(v) = resource_types {
let v = v.join(",");
builder = builder.query(&[("resourceTypes", v)]);
builder = builder.query(&[("resourceTypes", v.join(","))]);
}
let response = builder.send().await?;
Ok(error_check(response).await?.json().await?)
Expand Down Expand Up @@ -5953,8 +5951,7 @@ impl<TS: KeycloakTokenSupplier> KeycloakAdmin<TS> {
builder = builder.query(&[("max", v)]);
}
if let Some(v) = type_ {
let v = v.join(",");
builder = builder.query(&[("type", v)]);
builder = builder.query(&[("type", v.join(","))]);
}
if let Some(v) = user {
builder = builder.query(&[("user", v)]);
Expand Down

0 comments on commit 186d8b4

Please sign in to comment.