Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for vector query parameters. #872

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions progenitor-impl/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,14 +836,39 @@ impl Generator {
OperationParameterKind::Query(required) => {
let qn = &param.api_name;
let qn_ident = format_ident!("{}", &param.name);

let typ = if let OperationParameterType::Type(type_id) = &param.typ {
self.type_space.get_type(type_id).ok()
} else {
None
};

let assignment = typ
.and_then(|typ| {
match typ.details() {
typify::TypeDetails::Vec(_) => {
// Assume explode = true.
Some(quote! {
#qn_ident.iter().for_each(|item| {
#query_ident.push((#qn, item.to_string()));
})
})
}
_ => None,
}
})
.unwrap_or_else(|| {
quote! {
#query_ident.push((#qn, #qn_ident .to_string()));
}
});

let res = if *required {
quote! {
#query_ident.push((#qn, #qn_ident .to_string()));
}
assignment
} else {
quote! {
if let Some(v) = & #qn_ident {
#query_ident.push((#qn, v.to_string()));
if let Some(#qn_ident) = & #qn_ident {
#assignment
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions progenitor-impl/tests/output/src/buildomat_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2658,8 +2658,8 @@ pub mod builder {
encode_path(&task.to_string()),
);
let mut query = Vec::with_capacity(1usize);
if let Some(v) = &minseq {
query.push(("minseq", v.to_string()));
if let Some(minseq) = &minseq {
query.push(("minseq", minseq.to_string()));
}
#[allow(unused_mut)]
let mut request = client
Expand Down
4 changes: 2 additions & 2 deletions progenitor-impl/tests/output/src/buildomat_builder_tagged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2658,8 +2658,8 @@ pub mod builder {
encode_path(&task.to_string()),
);
let mut query = Vec::with_capacity(1usize);
if let Some(v) = &minseq {
query.push(("minseq", v.to_string()));
if let Some(minseq) = &minseq {
query.push(("minseq", minseq.to_string()));
}
#[allow(unused_mut)]
let mut request = client
Expand Down
4 changes: 2 additions & 2 deletions progenitor-impl/tests/output/src/buildomat_positional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,8 @@ impl Client {
encode_path(&task.to_string()),
);
let mut query = Vec::with_capacity(1usize);
if let Some(v) = &minseq {
query.push(("minseq", v.to_string()));
if let Some(minseq) = &minseq {
query.push(("minseq", minseq.to_string()));
}

#[allow(unused_mut)]
Expand Down
Loading