@@ -14,33 +14,54 @@ extension OpenAPI.Content {
14
14
public struct Encoding : Equatable {
15
15
public typealias Style = OpenAPI . Parameter . SchemaContext . Style
16
16
17
- public let contentType : OpenAPI . ContentType ?
17
+ /// If an encoding object only contains 1 content type, it will be populated here.
18
+ /// Two or more content types will result in a null value here but the `contentTypes`
19
+ /// (plural) property will contain all content types specified.
20
+ ///
21
+ /// The singular `contentType` property is only provided for backwards compatibility and
22
+ /// using the plural `contentTypes` property should be preferred.
23
+ @available ( * , deprecated, message: " use contentTypes instead " )
24
+ public var contentType : OpenAPI . ContentType ? {
25
+ guard let contentType = contentTypes. first,
26
+ contentTypes. count == 1 else {
27
+ return nil
28
+ }
29
+ return contentType
30
+ }
31
+
32
+ public let contentTypes : [ OpenAPI . ContentType ]
18
33
public let headers : OpenAPI . Header . Map ?
19
34
public let style : Style
20
35
public let explode : Bool
21
36
public let allowReserved : Bool
22
37
38
+ /// The singular `contentType` argument is only provided for backwards compatibility and
39
+ /// using the plural `contentTypes` argument should be preferred.
23
40
public init (
24
41
contentType: OpenAPI . ContentType ? = nil ,
42
+ contentTypes: [ OpenAPI . ContentType ] = [ ] ,
25
43
headers: OpenAPI . Header . Map ? = nil ,
26
44
style: Style = Self . defaultStyle,
27
45
allowReserved: Bool = false
28
46
) {
29
- self . contentType = contentType
47
+ self . contentTypes = contentTypes + [ contentType] . compactMap { $0 }
30
48
self . headers = headers
31
49
self . style = style
32
50
self . explode = style. defaultExplode
33
51
self . allowReserved = allowReserved
34
52
}
35
53
54
+ /// The singular `contentType` argument is only provided for backwards compatibility and
55
+ /// using the plural `contentTypes` argument should be preferred.
36
56
public init (
37
57
contentType: OpenAPI . ContentType ? = nil ,
58
+ contentTypes: [ OpenAPI . ContentType ] = [ ] ,
38
59
headers: OpenAPI . Header . Map ? = nil ,
39
60
style: Style = Self . defaultStyle,
40
61
explode: Bool ,
41
62
allowReserved: Bool = false
42
63
) {
43
- self . contentType = contentType
64
+ self . contentTypes = contentTypes + [ contentType] . compactMap { $0 }
44
65
self . headers = headers
45
66
self . style = style
46
67
self . explode = explode
@@ -56,7 +77,12 @@ extension OpenAPI.Content.Encoding: Encodable {
56
77
public func encode( to encoder: Encoder ) throws {
57
78
var container = encoder. container ( keyedBy: CodingKeys . self)
58
79
59
- try container. encodeIfPresent ( contentType, forKey: . contentType)
80
+ if contentTypes. count > 0 {
81
+ let contentTypesString = contentTypes
82
+ . map ( \. rawValue)
83
+ . joined ( separator: " , " )
84
+ try container. encode ( contentTypesString, forKey: . contentType)
85
+ }
60
86
try container. encodeIfPresent ( headers, forKey: . headers)
61
87
62
88
if style != Self . defaultStyle {
@@ -77,7 +103,16 @@ extension OpenAPI.Content.Encoding: Decodable {
77
103
public init ( from decoder: Decoder ) throws {
78
104
let container = try decoder. container ( keyedBy: CodingKeys . self)
79
105
80
- contentType = try container. decodeIfPresent ( OpenAPI . ContentType. self, forKey: . contentType)
106
+ let contentTypesString = try container. decodeIfPresent ( String . self, forKey: . contentType)
107
+ if let contentTypesString = contentTypesString {
108
+ contentTypes = contentTypesString
109
+ . split ( separator: " , " )
110
+ . compactMap { string in
111
+ OpenAPI . ContentType. init ( rawValue: string. trimmingCharacters ( in: . whitespaces) )
112
+ }
113
+ } else {
114
+ contentTypes = [ ]
115
+ }
81
116
82
117
headers = try container. decodeIfPresent ( OpenAPI . Header. Map. self, forKey: . headers)
83
118
0 commit comments