@@ -18,27 +18,6 @@ private protocol Wrapper {
1818}
1919extension Optional : Wrapper { }
2020
21- extension AnyJSONCaseIterable {
22- /// Given an array of Codable values, retrieve an array of AnyCodables.
23- static func allCases< T: Codable > ( from input: [ T ] , using encoder: JSONEncoder ) throws -> [ AnyCodable ] {
24- if let alreadyGoodToGo = input as? [ AnyCodable ] {
25- return alreadyGoodToGo
26- }
27-
28- // The following is messy, but it does get us the intended result:
29- // Given any array of things that can be encoded, we want
30- // to map to an array of AnyCodable so we can store later. We need to
31- // muck with JSONSerialization because something like an `enum` may
32- // very well be encoded as a string, and therefore representable
33- // by AnyCodable, but AnyCodable wants it to actually BE a String
34- // upon initialization.
35- guard let arrayOfCodables = try JSONSerialization . jsonObject ( with: encoder. encode ( input) , options: [ ] ) as? [ Any ] else {
36- throw OpenAPICodableError . allCasesArrayNotCodable
37- }
38- return arrayOfCodables. map ( AnyCodable . init)
39- }
40- }
41-
4221// MARK: Attribute
4322extension Attribute : OpenAPINodeType where RawValue: OpenAPINodeType {
4423 static public func openAPINode( ) throws -> JSONSchema {
@@ -101,14 +80,14 @@ extension Attribute: DateOpenAPINodeType where RawValue: DateOpenAPINodeType {
10180 }
10281}
10382
104- extension Attribute : AnyJSONCaseIterable where RawValue: CaseIterable , RawValue: Codable {
83+ extension Attribute : AnyRawRepresentable , AnyJSONCaseIterable where RawValue: CaseIterable , RawValue: Codable {
10584 public static func allCases( using encoder: JSONEncoder ) -> [ AnyCodable ] {
10685 return ( try ? allCases ( from: Array ( RawValue . allCases) , using: encoder) ) ?? [ ]
10786 }
10887}
10988
11089extension Attribute : AnyWrappedJSONCaseIterable where RawValue: AnyJSONCaseIterable {
111- public static func allCases ( using encoder: JSONEncoder ) -> [ AnyCodable ] {
90+ public static func wrappedAllCases ( using encoder: JSONEncoder ) -> [ AnyCodable ] {
11291 return RawValue . allCases ( using: encoder)
11392 }
11493}
@@ -175,14 +154,14 @@ extension TransformedAttribute: DateOpenAPINodeType where RawValue: DateOpenAPIN
175154 }
176155}
177156
178- extension TransformedAttribute : AnyJSONCaseIterable where RawValue: CaseIterable , RawValue: Codable {
157+ extension TransformedAttribute : AnyRawRepresentable , AnyJSONCaseIterable where RawValue: CaseIterable , RawValue: Codable {
179158 public static func allCases( using encoder: JSONEncoder ) -> [ AnyCodable ] {
180159 return ( try ? allCases ( from: Array ( RawValue . allCases) , using: encoder) ) ?? [ ]
181160 }
182161}
183162
184163extension TransformedAttribute : AnyWrappedJSONCaseIterable where RawValue: AnyJSONCaseIterable {
185- public static func allCases ( using encoder: JSONEncoder ) -> [ AnyCodable ] {
164+ public static func wrappedAllCases ( using encoder: JSONEncoder ) -> [ AnyCodable ] {
186165 return RawValue . allCases ( using: encoder)
187166 }
188167}
0 commit comments