I wonder if we could have something like this (pseudocode):
enum Response: String, Codable {
case error(ErrorRecord) = "Error"
case hello(HelloRecord) // only specified when needed
case list(ListRecord) = "List"
}
I know it looks a bit weird with associated values.
Or this:
enum Response: Codable {
case error(ErrorRecord) #jsonname("Error")
case hello(HelloRecord) // only specified when needed
case list(ListRecord) #jsonname("List")
}
Unfortunately the schema is a little loopy, to be charitable. It's also set in stone because I'm implementing the protocol of another application. There are a lot of cases I have Bool? types because it interchangeably uses false and null, passing doubles and strings in the same field, or worse, a case where it can be a boolean or the string "null" (I wish I was joking...). I have to do manual decoding a lot for these situations. Realistically, these are bugs in the server implementation, but one no one really noticed because the client and server are Python.
Good tip on the key decoding strategy - thankfully it only uses it though on the root value.