@@ -118,20 +118,39 @@ extension OpenAPI.Content {
118118}
119119
120120extension OpenAPI . Content {
121- public struct Encoding : Codable , Equatable {
121+ public struct Encoding : Equatable {
122+ public typealias Style = OpenAPI . PathItem . Parameter . Schema . Style
123+
122124 public let contentType : OpenAPI . ContentType ?
123125 public let headers : OpenAPI . Header . Map ?
124- // public let style: String?
125- // public let explode: Bool (defaults for this need to be tied to style making style a good candidate for abstraction)
126+ public let style : Style
127+ public let explode : Bool
126128 public let allowReserved : Bool
127129
128130 public init ( contentType: OpenAPI . ContentType ? = nil ,
129131 headers: OpenAPI . Header . Map ? = nil ,
132+ style: Style = Self . defaultStyle,
133+ allowReserved: Bool = false ) {
134+ self . contentType = contentType
135+ self . headers = headers
136+ self . style = style
137+ self . explode = style. defaultExplode
138+ self . allowReserved = allowReserved
139+ }
140+
141+ public init ( contentType: OpenAPI . ContentType ? = nil ,
142+ headers: OpenAPI . Header . Map ? = nil ,
143+ style: Style = Self . defaultStyle,
144+ explode: Bool ,
130145 allowReserved: Bool = false ) {
131146 self . contentType = contentType
132147 self . headers = headers
148+ self . style = style
149+ self . explode = explode
133150 self . allowReserved = allowReserved
134151 }
152+
153+ public static let defaultStyle : Style = . default( for: . query)
135154 }
136155}
137156
@@ -160,16 +179,9 @@ extension OpenAPI.Content: Encodable {
160179 try container. encode ( example, forKey: . example)
161180 }
162181
163- if encoding != nil {
164- try container. encode ( encoding, forKey: . encoding)
165- }
182+ try encoding. encodeIfNotNil ( to: & container, forKey: . encoding)
166183
167- if vendorExtensions != [ : ] {
168- for (key, value) in vendorExtensions {
169- let xKey = key. starts ( with: " x- " ) ? key : " x- \( key) "
170- try container. encode ( value, forKey: . extended( xKey) )
171- }
172- }
184+ try encodeExtensions ( to: & container)
173185 }
174186}
175187
@@ -256,3 +268,54 @@ extension OpenAPI.Content {
256268 }
257269 }
258270}
271+
272+ // MARK: Content.Encoding
273+
274+ extension OpenAPI . Content . Encoding : Encodable {
275+ public func encode( to encoder: Encoder ) throws {
276+ var container = encoder. container ( keyedBy: CodingKeys . self)
277+
278+ try contentType. encodeIfNotNil ( to: & container, forKey: . contentType)
279+
280+ try headers. encodeIfNotNil ( to: & container, forKey: . headers)
281+
282+ if style != Self . defaultStyle {
283+ try container. encode ( style, forKey: . style)
284+ }
285+
286+ if explode != style. defaultExplode {
287+ try container. encode ( explode, forKey: . explode)
288+ }
289+
290+ if allowReserved != false {
291+ try container. encode ( allowReserved, forKey: . allowReserved)
292+ }
293+ }
294+ }
295+
296+ extension OpenAPI . Content . Encoding : Decodable {
297+ public init ( from decoder: Decoder ) throws {
298+ let container = try decoder. container ( keyedBy: CodingKeys . self)
299+
300+ contentType = try container. decodeIfPresent ( OpenAPI . ContentType. self, forKey: . contentType)
301+
302+ headers = try container. decodeIfPresent ( OpenAPI . Header. Map. self, forKey: . headers)
303+
304+ let style : Style = try container. decodeIfPresent ( Style . self, forKey: . style) ?? Self . defaultStyle
305+ self . style = style
306+
307+ explode = try container. decodeIfPresent ( Bool . self, forKey: . explode) ?? style. defaultExplode
308+
309+ allowReserved = try container. decodeIfPresent ( Bool . self, forKey: . allowReserved) ?? false
310+ }
311+ }
312+
313+ extension OpenAPI . Content . Encoding {
314+ private enum CodingKeys : String , CodingKey {
315+ case contentType
316+ case headers
317+ case style
318+ case explode
319+ case allowReserved
320+ }
321+ }
0 commit comments