Skip to content

Choose the serialization method based on content type #43

Closed
apple/swift-openapi-runtime
#12
@czechboy0

Description

@czechboy0

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.

From: apple/swift-openapi-runtime#10

Metadata

Metadata

Assignees

Labels

area/runtimeAffects: the runtime library.kind/bugFeature doesn't work as expected.size/LLarge task. (A couple of weeks of work.)🔨 semver/patchNo public API change.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions