Skip to content

Migrate header, path param, query param serialization to URI coder, deprecate _StringConvertible #144

@czechboy0

Description

@czechboy0

Today, one can only use _StringConvertible types in places like query parameters, headers, and so on.

This works well for native primitive types, like String, Int, Double, and Bool; and we also made it work for string-based generated enums (which are essentially strings with an extra constraint).

However, when used with, for example, a oneOf that is either a string or an int, this doesn't work, as we generate an enum with associated values, and even though all the underlying cases are themselves _StringConvertible, the oneOf itself isn't. That prevents adopters from doing things that are legal in OpenAPI, and can be pretty useful (an example is the Weather.gov OpenAPI doc described in #135).

A solution to this could look as follows:

  • if all subschemas of a oneOf/allOf/anyOf are _StringConvertible (we have util functions in the generator already to check this), add the RawRepresentable and _AutoLosslessStringConvertible conformances on the type itself as well
  • this will require generating a custom init(rawValue:) initializer and a rawValue property getter, but we also already did that for string-based enums, so we can take inspiration there
  • note: in the rawValue property getter, we should dynamically check the undocumented contents of the OpenAPIRuntime.OpenAPIValueContainer, and if it's itself convertible to string, return it, but otherwise throw an error – this is for cases when e.g. an object was provided, we don't want to stringify it

Once this is in place, compositions of _StringConvertible types will also be _StringConvertible, and will be usable in those contexts, especially in query and header parameters.

Metadata

Metadata

Assignees

Labels

area/generatorAffects: plugin, CLI, config file.area/openapiAdding/updating a feature defined in OpenAPI.size/MMedium task. (A couple of days of work.)

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions