From f8e3c28ab5feeec53e807c9df0ad8cc9da40fedb Mon Sep 17 00:00:00 2001 From: repjarms Date: Tue, 18 Aug 2020 11:48:46 -0400 Subject: [PATCH] fix(hand edit): serialize enrichment parameter based on the generated output, this would write the swift struct literal to the form data. this change serializes the struct into json before appending. --- Source/DiscoveryV2/Discovery.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/DiscoveryV2/Discovery.swift b/Source/DiscoveryV2/Discovery.swift index 5c42519cd..3c7990b5f 100644 --- a/Source/DiscoveryV2/Discovery.swift +++ b/Source/DiscoveryV2/Discovery.swift @@ -57,7 +57,7 @@ public class Discovery { */ public init(version: String) throws { self.version = version - + let authenticator = try ConfigBasedAuthenticatorFactory.getAuthenticator(credentialPrefix: serviceSdkName) self.authenticator = authenticator @@ -1539,8 +1539,15 @@ public class Discovery { multipartFormData.append(enrichmentData, withName: "enrichment") } if let file = file { - multipartFormData.append(file, withName: "file", fileName: "filename") + multipartFormData.append(file, withName: "file", mimeType: "application/octet-stream", fileName: "filename") + } + + guard let enrichmentJSON = try? JSON.encoder.encode(enrichment) else { + completionHandler(nil, WatsonError.serialization(values: "request body")) + return } + multipartFormData.append(enrichmentJSON, withName: "enrichment") + guard let body = try? multipartFormData.toData() else { completionHandler(nil, WatsonError.serialization(values: "request multipart form data")) return