Skip to content

Commit

Permalink
validate required input query params (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Nov 22, 2022
1 parent dfd9b20 commit 959146f
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -856,17 +856,21 @@ private void writeRequestQueryParam(
target
);

boolean isRequired = binding.getMember().isRequired();
writer.addImport("expectNonNull", "__expectNonNull", "@aws-sdk/smithy-client");
String value = isRequired ? "__expectNonNull($L, `" + memberName + "`)" : "$L";

if (Objects.equals("input." + memberName + "!", queryValue)) {
// simple undefined check
writer.write(
"$S: [,$L],",
"$S: [," + value + "],",
binding.getLocationName(),
queryValue
);
} else {
// undefined check with lazy eval
writer.write(
"$S: [() => input.$L !== void 0, () => $L],",
"$S: [() => input.$L !== void 0, () => " + value + "],",
binding.getLocationName(),
memberName,
queryValue
Expand Down

0 comments on commit 959146f

Please sign in to comment.