Skip to content

Commit bd2203d

Browse files
committed
update to OpenAPIKit 0.9.0, add exports for OpenAPIKit and JSONAPI
1 parent ceb5021 commit bd2203d

File tree

6 files changed

+16
-210
lines changed

6 files changed

+16
-210
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
.package(url: "https://github.com/Flight-School/AnyCodable.git", .upToNextMinor(from: "0.2.2")),
1515
.package(url: "https://github.com/mattpolzin/Sampleable.git", .upToNextMajor(from: "2.0.0")),
1616
.package(url: "https://github.com/mattpolzin/JSONAPI.git", .upToNextMajor(from: "3.0.0")),
17-
.package(url: "https://github.com/mattpolzin/OpenAPI.git", .upToNextMinor(from: "0.8.0")),
17+
.package(url: "https://github.com/mattpolzin/OpenAPI.git", .upToNextMinor(from: "0.9.0")),
1818
.package(url: "https://github.com/typelift/SwiftCheck.git", .upToNextMinor(from: "0.12.0"))
1919
],
2020
targets: [
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// Exports.swift
3+
// JSONAPIOpenAPI
4+
//
5+
// Created by Mathew Polzin on 12/15/19.
6+
//
7+
8+
@_exported import JSONAPI
9+
@_exported import OpenAPIKit

Sources/JSONAPIOpenAPI/JSONAPI/JSONAPIAttribute+OpenAPI.swift

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,6 @@ private protocol Wrapper {
1818
}
1919
extension 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
4322
extension 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

11089
extension 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

184163
extension 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
}

Sources/JSONAPIOpenAPI/OpenAPIErrors.swift

Lines changed: 0 additions & 19 deletions
This file was deleted.

Sources/JSONAPIOpenAPI/Sampleable/Sampleable+OpenAPI.swift

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)