Skip to content

Commit 749c379

Browse files
author
Ed Paulosky
authored
fix: No-ops instead of encoding empty string when encoding an empty body in xml (#481)
* Removes logic for case where the payload member is nil * Fixes tests after adjusting HttpBodyMiddleware * Correctly renders empty bodies
1 parent 3089e37 commit 749c379

File tree

2 files changed

+1
-12
lines changed

2 files changed

+1
-12
lines changed

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/middlewares/handlers/HttpBodyMiddleware.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,11 @@ class HttpBodyMiddleware(
111111
renderEncodedBodyAddedToRequest(bodyDeclaration, dataDeclaration)
112112
}
113113
writer.indent()
114-
writer.openBlock("if encoder is JSONEncoder {", "} else if encoder is XMLEncoder {") {
114+
writer.openBlock("if encoder is JSONEncoder {", "}") {
115115
writer.write("// Encode an empty body as an empty structure in JSON")
116116
writer.write("let \$L = \"{}\".data(using: .utf8)!", dataDeclaration)
117117
renderEncodedBodyAddedToRequest(bodyDeclaration, dataDeclaration)
118118
}
119-
writer.indent()
120-
writer.write("// Encode an empty body as an empty string in XML")
121-
writer.write("let \$L = \"\".data(using: .utf8)!", dataDeclaration)
122-
renderEncodedBodyAddedToRequest(bodyDeclaration, dataDeclaration)
123-
writer.dedent()
124-
writer.write("}")
125119
writer.dedent()
126120
writer.write("}")
127121
}

smithy-swift-codegen/src/test/kotlin/HttpBodyMiddlewareTests.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ class HttpBodyMiddlewareTests {
160160
let payload1data = "{}".data(using: .utf8)!
161161
let payload1body = ClientRuntime.HttpBody.data(payload1data)
162162
input.builder.withBody(payload1body)
163-
} else if encoder is XMLEncoder {
164-
// Encode an empty body as an empty string in XML
165-
let payload1data = "".data(using: .utf8)!
166-
let payload1body = ClientRuntime.HttpBody.data(payload1data)
167-
input.builder.withBody(payload1body)
168163
}
169164
}
170165
} catch let err {

0 commit comments

Comments
 (0)