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

Fix query parameters in SSDK #449

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,7 @@ private ObjectNode buildQueryBag(List<String> queryParams) {

ObjectNode.Builder nodeBuilder = ObjectNode.objectNodeBuilder();
for (Map.Entry<String, List<String>> entry : query.entrySet()) {
// The value of the query bag can either be a single string or a list, so we need to ensure individual
// values are written out as individual strings.
if (entry.getValue().size() == 1) {
nodeBuilder.withMember(entry.getKey(), StringNode.from(entry.getValue().get(0)));
} else {
nodeBuilder.withMember(entry.getKey(), ArrayNode.fromStrings(entry.getValue()));
}
nodeBuilder.withMember(entry.getKey(), ArrayNode.fromStrings(entry.getValue()));
}
return nodeBuilder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1829,13 +1829,22 @@ private void readDirectQueryBindings(GenerationContext context, List<HttpBinding
writer.addImport("SerializationException",
"__SerializationException",
"@aws-smithy/server-common");
writer.openBlock("if (Array.isArray(query[$1S])) {", "}",
writer.write("let queryValue: string;");
writer.openBlock("if (Array.isArray(query[$S])) {", "}",
binding.getLocationName(),
() -> {
writer.write("throw new __SerializationException();");
writer.openBlock("if (query[$S].length === 1) {", "}",
binding.getLocationName(),
() -> {
writer.write("queryValue = query[$S][0];", binding.getLocationName());
});
writer.openBlock("else {", "}", () -> {
writer.write("throw new __SerializationException();");
});
});
writer.write("const queryValue = query[$1S] as string;",
binding.getLocationName());
writer.openBlock("else {", "}", () -> {
writer.write("queryValue = query[$S] as string;", binding.getLocationName());
});
}
String queryValue = getOutputValue(context, binding.getLocation(), "queryValue",
binding.getMember(), target);
Expand All @@ -1855,6 +1864,7 @@ private void readMappedQueryBindings(GenerationContext context, HttpBinding mapp
}
writer.write("let parsedQuery: { [key: string]: $L } = {}", valueType);
writer.openBlock("for (const [key, value] of Object.entries(query)) {", "}", () -> {
writer.write("let queryValue: string;");
final String parsedValue;
if (valueShape instanceof CollectionShape) {
writer.write("const valueArray = Array.isArray(value) ? (value as string[]) : [value as string];");
Expand All @@ -1866,10 +1876,19 @@ private void readMappedQueryBindings(GenerationContext context, HttpBinding mapp
"@aws-smithy/server-common");
writer.openBlock("if (Array.isArray(value)) {", "}",
() -> {
writer.write("throw new __SerializationException();");
writer.openBlock("if (value.length === 1) {", "}",
() -> {
writer.write("queryValue = value[0];");
});
writer.openBlock("else {", "}", () -> {
writer.write("throw new __SerializationException();");
});
});
writer.openBlock("else {", "}", () -> {
writer.write("queryValue = value as string;");
});
parsedValue = getOutputValue(context, mappedBinding.getLocation(),
"value as string", target.getValue(), valueShape);
"queryValue", target.getValue(), valueShape);
}
writer.write("parsedQuery[key] = $L;", parsedValue);
});
Expand Down