Not crazy about how I got there, but now it is relatively easy to print arbitrary enum's allCases as the list of possible values in the format specced out by OpenAPI.

This commit is contained in:
Mathew Polzin
2019-01-20 15:39:54 -08:00
parent cf746e182f
commit dc42ec27fc
5 changed files with 77 additions and 92 deletions
@@ -6,6 +6,7 @@
//
import JSONAPI
import AnyCodable
private protocol _Optional {}
extension Optional: _Optional {}
@@ -32,14 +33,14 @@ extension Attribute: RawOpenAPINodeType where RawValue: RawRepresentable, RawVal
}
}
extension Attribute: AnyJSONCaseIterable where RawValue: CaseIterable {
public static var allCases: [Any] {
return Array(RawValue.allCases)
extension Attribute: AnyJSONCaseIterable where RawValue: CaseIterable, RawValue: Codable {
public static var allCases: [AnyCodable] {
return (try? allCases(from: Array(RawValue.allCases))) ?? []
}
}
extension Attribute: AnyWrappedJSONCaseIterable where RawValue: AnyJSONCaseIterable {
public static var allCases: [Any] {
public static var allCases: [AnyCodable] {
return RawValue.allCases
}
}