File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed
main/kotlin/software/amazon/smithy/swift/codegen/integration/middlewares/handlers Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -111,10 +111,19 @@ class HttpBodyMiddleware(
111111 renderEncodedBodyAddedToRequest(bodyDeclaration, dataDeclaration)
112112 }
113113 writer.indent()
114- writer.write(" let $dataDeclaration = try encoder.encode(input.operationInput)" )
114+ writer.openBlock(" if encoder is JSONEncoder {" , " } else if encoder is XMLEncoder {" ) {
115+ writer.write(" // Encode an empty body as an empty structure in JSON" )
116+ writer.write(" let \$ L = \" {}\" .data(using: .utf8)!" , dataDeclaration)
117+ renderEncodedBodyAddedToRequest(bodyDeclaration, dataDeclaration)
118+ }
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)
115122 renderEncodedBodyAddedToRequest(bodyDeclaration, dataDeclaration)
116123 writer.dedent()
117124 writer.write(" }" )
125+ writer.dedent()
126+ writer.write(" }" )
118127 }
119128 renderErrorCase()
120129 }
Original file line number Diff line number Diff line change @@ -155,9 +155,17 @@ class HttpBodyMiddlewareTests {
155155 let payload1body = ClientRuntime.HttpBody.data(payload1data)
156156 input.builder.withBody(payload1body)
157157 } else {
158- let payload1data = try encoder.encode(input.operationInput)
159- let payload1body = ClientRuntime.HttpBody.data(payload1data)
160- input.builder.withBody(payload1body)
158+ if encoder is JSONEncoder {
159+ // Encode an empty body as an empty structure in JSON
160+ let payload1data = "{}".data(using: .utf8)!
161+ let payload1body = ClientRuntime.HttpBody.data(payload1data)
162+ 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)
168+ }
161169 }
162170 } catch let err {
163171 throw SdkError<ExplicitStructOutputError>.client(ClientRuntime.ClientError.serializationFailed(err.localizedDescription))
You can’t perform that action at this time.
0 commit comments