Skip to content

Commit 432b1dd

Browse files
Strictly parse booleans in http bindings
1 parent 09f87a7 commit 432b1dd

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,7 +2403,7 @@ private String getOutputValue(
24032403
if (target instanceof NumberShape) {
24042404
return getNumberOutputParam(bindingType, dataSource, target);
24052405
} else if (target instanceof BooleanShape) {
2406-
return getBooleanOutputParam(bindingType, dataSource);
2406+
return getBooleanOutputParam(context, bindingType, dataSource);
24072407
} else if (target instanceof StringShape) {
24082408
return getStringOutputParam(context, bindingType, dataSource, target);
24092409
} else if (target instanceof DocumentShape) {
@@ -2427,21 +2427,21 @@ private String getOutputValue(
24272427

24282428
/**
24292429
* Given context and a source of data, generate an output value provider for the
2430-
* boolean. By default, this checks strict equality to 'true'in headers and passes
2430+
* boolean. By default, this checks strict equality to 'true' in headers and passes
24312431
* through for documents.
24322432
*
24332433
* @param bindingType How this value is bound to the operation output.
24342434
* @param dataSource The in-code location of the data to provide an output of
24352435
* ({@code output.foo}, {@code entry}, etc.)
24362436
* @return Returns a value or expression of the output boolean.
24372437
*/
2438-
private String getBooleanOutputParam(Location bindingType, String dataSource) {
2438+
private String getBooleanOutputParam(GenerationContext context, Location bindingType, String dataSource) {
24392439
switch (bindingType) {
2440-
// TODO: make sure this actually works
24412440
case QUERY:
24422441
case LABEL:
24432442
case HEADER:
2444-
return dataSource + " === 'true'";
2443+
context.getWriter().addImport("parseBoolean", "__parseBoolean", "@aws-sdk/smithy-client");
2444+
return String.format("__parseBoolean(%s)", dataSource);
24452445
default:
24462446
throw new CodegenException("Unexpected boolean binding location `" + bindingType + "`");
24472447
}
@@ -2487,7 +2487,6 @@ private String getBlobOutputParam(Location bindingType, String dataSource) {
24872487
switch (bindingType) {
24882488
case PAYLOAD:
24892489
return dataSource;
2490-
// TODO: make sure this actually works
24912490
case QUERY:
24922491
case LABEL:
24932492
case HEADER:
@@ -2604,7 +2603,6 @@ private String getNamedMembersOutputParam(
26042603
*/
26052604
private String getNumberOutputParam(Location bindingType, String dataSource, Shape target) {
26062605
switch (bindingType) {
2607-
// TODO: validate the assumption that query works the same here
26082606
case QUERY:
26092607
case LABEL:
26102608
case HEADER:

0 commit comments

Comments
 (0)