Description
Currently, the generator chooses the serialization method (JSON, text-based, or raw data) based on the type used in the request/response body. Most of the time, that works correctly, but there are some corner cases, such as:
- content type: application/json, the body is a fragment string (as opposed to a JSON container, like an object or an array).
In this case, we today serialize it using LosslessStringConvertible
, and end up without the quotes. That's only correct if the content type is text/plain
(and in fact was just fixed in apple/swift-openapi-runtime#9).
Action: add logic for choosing the serialization method based on the content type, instead of trying to deduce it from the Swift type.
Whilst implementing this change, I think that we may want to revisit the encoding logic, since I think the knowledge of whether to encode a value as binary data, JSON, or plain text, is at the place where the content-type is set, but we'll defer that to a subsequent PR.