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
@@ -5,6 +5,8 @@
// Created by Mathew Polzin on 01/13/19.
//
import AnyCodable
/**
Notable omissions in this library's default offerings:
@@ -41,9 +43,9 @@ extension Optional: RawOpenAPINodeType where Wrapped: RawRepresentable, Wrapped.
}
}
extension Optional: AnyJSONCaseIterable where Wrapped: CaseIterable {
public static var allCases: [Any] {
return Array(Wrapped.allCases)
extension Optional: AnyJSONCaseIterable where Wrapped: CaseIterable, Wrapped: Codable {
public static var allCases: [AnyCodable] {
return (try? allCases(from: Array(Wrapped.allCases))) ?? []
}
}