Skip to content

Commit

Permalink
generate apis with seperately query params
Browse files Browse the repository at this point in the history
  • Loading branch information
vctqs1 committed Apr 21, 2024
1 parent b40d8c6 commit a1aab35
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,31 @@ impl<'a> Transpiler<'a> {
paths: &[postman::PathElement],
security_requirement: Option<Vec<SecurityRequirement>>,
) {
let resolved_segments = paths
let mut paths_with_query = paths.to_vec(); // Clone the elements of paths into a new vector
if url.query.is_some() {
let query_string = url.query.as_ref().unwrap()
.iter()
.map(|param| {
format!(
"{}={}",
param.key.as_ref().unwrap_or(&"".to_string()).as_str(), // Handle None value
param.value.as_ref().unwrap_or(&"".to_string()).as_str() // Handle None value
)
})
.collect::<Vec<String>>()
.join("&");

paths_with_query.push(postman::PathElement::String(format!("?{}", query_string))); // Append the new element
}
// Filter empty path elements
paths_with_query.retain(|segment| {
match segment {
postman::PathElement::PathClass(c) => c.value.is_some(),
postman::PathElement::String(c) => !c.is_empty(),
}
});

let resolved_segments = paths_with_query
.iter()
.map(|segment| {
let mut seg = match segment {
Expand Down

0 comments on commit a1aab35

Please sign in to comment.