Thanks for that response. I suspected something like this but hoped for something different ![]()
Essentially, I use OpenApi generator to create a pod that contains the network code to interact with a REST API. Unfortunately, the REST client does not send the data correctly (it sends a string containing a JSON object instead of the JSON object directly), so the code generated does not work for this specific class.
So the override that I create simply decode the data as a string, re-encodes it as an object and decodes it as the object...
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
let statusesString = try? values.decode(String.self, forKey: .statuses)
var decodedStatuses = [Status]()
if let statusData = statusesString?.data(using: .utf8) {
let decodeResult = CodableHelper.decode([Status].self, from: statusData)
switch decodeResult {
case let .success(parsedStatuses):
decodedStatuses = parsedStatuses
case let .failure(error):
throw (error)
}
}
self.init(..., statuses:decodedStatuses)
}
I can patch the pod that I generate, but I'd love to keep the modification outside of the pod so it does not get deleted when the pod is regenerated... (I have already done that mistake once :-))