@@ -14,33 +14,54 @@ extension OpenAPI.Content {
1414    public  struct  Encoding :  Equatable  { 
1515        public  typealias  Style  =  OpenAPI . Parameter . SchemaContext . Style 
1616
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 ] 
1833        public  let  headers :  OpenAPI . Header . Map ? 
1934        public  let  style :  Style 
2035        public  let  explode :  Bool 
2136        public  let  allowReserved :  Bool 
2237
38+         /// The singular `contentType` argument is only provided for backwards compatibility and
39+         /// using the plural `contentTypes` argument should be preferred.
2340        public  init ( 
2441            contentType:  OpenAPI . ContentType ? =  nil , 
42+             contentTypes:  [ OpenAPI . ContentType ]  =  [ ] , 
2543            headers:  OpenAPI . Header . Map ? =  nil , 
2644            style:  Style  =  Self . defaultStyle, 
2745            allowReserved:  Bool  =  false 
2846        )  { 
29-             self . contentType  =  contentType
47+             self . contentTypes  =  contentTypes  +   [ contentType] . compactMap   {  $0  } 
3048            self . headers =  headers
3149            self . style =  style
3250            self . explode =  style. defaultExplode
3351            self . allowReserved =  allowReserved
3452        } 
3553
54+         /// The singular `contentType` argument is only provided for backwards compatibility and
55+         /// using the plural `contentTypes` argument should be preferred.
3656        public  init ( 
3757            contentType:  OpenAPI . ContentType ? =  nil , 
58+             contentTypes:  [ OpenAPI . ContentType ]  =  [ ] , 
3859            headers:  OpenAPI . Header . Map ? =  nil , 
3960            style:  Style  =  Self . defaultStyle, 
4061            explode:  Bool , 
4162            allowReserved:  Bool  =  false 
4263        )  { 
43-             self . contentType  =  contentType
64+             self . contentTypes  =  contentTypes  +   [ contentType] . compactMap   {  $0  } 
4465            self . headers =  headers
4566            self . style =  style
4667            self . explode =  explode
@@ -56,7 +77,12 @@ extension OpenAPI.Content.Encoding: Encodable {
5677    public  func  encode( to encoder:  Encoder )  throws  { 
5778        var  container  =  encoder. container ( keyedBy:  CodingKeys . self) 
5879
59-         try . encodeIfPresent ( contentType,  forKey:  . contentType) 
80+         if  contentTypes. count >  0  { 
81+             let  contentTypesString  =  contentTypes
82+                 . map ( \. rawValue) 
83+                 . joined ( separator:  " ,  " ) 
84+             try . encode ( contentTypesString,  forKey:  . contentType) 
85+         } 
6086        try . encodeIfPresent ( headers,  forKey:  . headers) 
6187
6288        if  style !=  Self . defaultStyle { 
@@ -77,7 +103,16 @@ extension OpenAPI.Content.Encoding: Decodable {
77103    public  init ( from decoder:  Decoder )  throws  { 
78104        let  container  =  try . container ( keyedBy:  CodingKeys . self) 
79105
80-         contentType =  try . decodeIfPresent ( OpenAPI . ContentType. self,  forKey:  . contentType) 
106+         let  contentTypesString  =  try . 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+         } 
81116
82117        headers =  try . decodeIfPresent ( OpenAPI . Header. Map. self,  forKey:  . headers) 
83118
0 commit comments