Skip to content

Commit

Permalink
validate required input query params (smithy-lang#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored and srchase committed Mar 17, 2023
1 parent eba5170 commit 077aab7
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 077aab7

Please sign in to comment.