Skip to content

Define query while declaring #177

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

Merged
merged 1 commit into from
May 11, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -316,28 +316,27 @@ private boolean writeRequestQueryString(

// Build the initial query bag.
Map<String, String> queryLiterals = trait.getUri().getQueryLiterals();
if (!queryLiterals.isEmpty()) {
// Write any query literals present in the uri.
writer.openBlock("const query: any = {", "};",
() -> queryLiterals.forEach((k, v) -> writer.write("$S: $S,", k, v)));
} else if (!queryBindings.isEmpty()) {
writer.write("const query: any = {};");
}

// Handle any additional query bindings.
if (!queryBindings.isEmpty()) {
Model model = context.getModel();
for (HttpBinding binding : queryBindings) {
String memberName = symbolProvider.toMemberName(binding.getMember());
writer.addImport("extendedEncodeURIComponent", "__extendedEncodeURIComponent",
"@aws-sdk/smithy-client");
writer.openBlock("if (input.$L !== undefined) {", "}", memberName, () -> {
Shape target = model.expectShape(binding.getMember().getTarget());
String queryValue = getInputValue(context, binding.getLocation(), "input." + memberName,
binding.getMember(), target);
writer.write("query[$S] = $L;", binding.getLocationName(), queryValue);
});
}
if (!queryLiterals.isEmpty() || !queryBindings.isEmpty()) {
writer.openBlock("const query: any = {", "};", () -> {
if (!queryLiterals.isEmpty()) {
// Write any query literals present in the uri.
queryLiterals.forEach((k, v) -> writer.write("$S: $S,", k, v));
}
// Handle any additional query bindings.
if (!queryBindings.isEmpty()) {
Model model = context.getModel();
for (HttpBinding binding : queryBindings) {
String memberName = symbolProvider.toMemberName(binding.getMember());
writer.addImport("extendedEncodeURIComponent", "__extendedEncodeURIComponent",
"@aws-sdk/smithy-client");
Shape target = model.expectShape(binding.getMember().getTarget());
String queryValue = getInputValue(context, binding.getLocation(), "input." + memberName,
binding.getMember(), target);
writer.write("...(input.$L !== undefined && { $S: $L }),", memberName,
binding.getLocationName(), queryValue);
}
}
});
}

// Any binding or literal means we generated a query bag.
Expand Down