Skip to content

Strictly parse booleans in http bindings #364

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
Jun 25, 2021
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 @@ -2403,7 +2403,7 @@ private String getOutputValue(
if (target instanceof NumberShape) {
return getNumberOutputParam(bindingType, dataSource, target);
} else if (target instanceof BooleanShape) {
return getBooleanOutputParam(bindingType, dataSource);
return getBooleanOutputParam(context, bindingType, dataSource);
} else if (target instanceof StringShape) {
return getStringOutputParam(context, bindingType, dataSource, target);
} else if (target instanceof DocumentShape) {
Expand All @@ -2427,21 +2427,21 @@ private String getOutputValue(

/**
* Given context and a source of data, generate an output value provider for the
* boolean. By default, this checks strict equality to 'true'in headers and passes
* boolean. By default, this checks strict equality to 'true' in headers and passes
* through for documents.
*
* @param bindingType How this value is bound to the operation output.
* @param dataSource The in-code location of the data to provide an output of
* ({@code output.foo}, {@code entry}, etc.)
* @return Returns a value or expression of the output boolean.
*/
private String getBooleanOutputParam(Location bindingType, String dataSource) {
private String getBooleanOutputParam(GenerationContext context, Location bindingType, String dataSource) {
switch (bindingType) {
// TODO: make sure this actually works
case QUERY:
case LABEL:
case HEADER:
return dataSource + " === 'true'";
context.getWriter().addImport("parseBoolean", "__parseBoolean", "@aws-sdk/smithy-client");
return String.format("__parseBoolean(%s)", dataSource);
default:
throw new CodegenException("Unexpected boolean binding location `" + bindingType + "`");
}
Expand Down Expand Up @@ -2487,7 +2487,6 @@ private String getBlobOutputParam(Location bindingType, String dataSource) {
switch (bindingType) {
case PAYLOAD:
return dataSource;
// TODO: make sure this actually works
case QUERY:
case LABEL:
case HEADER:
Expand Down Expand Up @@ -2604,7 +2603,6 @@ private String getNamedMembersOutputParam(
*/
private String getNumberOutputParam(Location bindingType, String dataSource, Shape target) {
switch (bindingType) {
// TODO: validate the assumption that query works the same here
case QUERY:
case LABEL:
case HEADER:
Expand Down