Skip to content

Commit 2252c2c

Browse files
committed
remove FineJSON dependency (not currently building for Swift 5.4 anyway) by using Yams for all order-dependent testing. add nightly Swift 5.4 CI step.
1 parent 4ca96ed commit 2252c2c

File tree

6 files changed

+68
-301
lines changed

6 files changed

+68
-301
lines changed

Package.resolved

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

Package.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ let package = Package(
1414
targets: ["OpenAPIKit"]),
1515
],
1616
dependencies: [
17-
.package(url: "https://github.com/jpsim/Yams.git", from: "4.0.0"), // just for tests
18-
.package(url: "https://github.com/omochi/FineJSON.git", from: "1.14.0") // just for tests
17+
.package(url: "https://github.com/jpsim/Yams.git", from: "4.0.0") // just for tests
1918
],
2019
targets: [
2120
.target(
2221
name: "OpenAPIKit",
2322
dependencies: []),
2423
.testTarget(
2524
name: "OpenAPIKitTests",
26-
dependencies: ["OpenAPIKit", "Yams", "FineJSON"]),
25+
dependencies: ["OpenAPIKit", "Yams"]),
2726
.testTarget(
2827
name: "OpenAPIKitCompatibilitySuite",
2928
dependencies: ["OpenAPIKit", "Yams"]),
@@ -35,7 +34,7 @@ let package = Package(
3534
dependencies: ["OpenAPIKit"]),
3635
.testTarget(
3736
name: "OrderedDictionaryTests",
38-
dependencies: ["OpenAPIKit", "Yams", "FineJSON"]),
37+
dependencies: ["OpenAPIKit", "Yams"]),
3938
.testTarget(
4039
name: "AnyCodableTests",
4140
dependencies: ["OpenAPIKit"])

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ You can use this same validation system to dig arbitrarily deep into an OpenAPI
7676
### A note on dictionary ordering
7777
The **Foundation** library's `JSONEncoder` and `JSONDecoder` do not make any guarantees about the ordering of keyed containers. This means decoding a JSON OpenAPI Document and then encoding again might result in the document's various hashed structures being in a different order.
7878

79-
If retaining order is important for your use-case, I recommend the [**Yams**](https://github.com/jpsim/Yams) and [**FineJSON**](https://github.com/omochi/FineJSON) libraries for YAML and JSON respectively.
79+
If retaining order is important for your use-case, I recommend the [**Yams**](https://github.com/jpsim/Yams) and [**FineJSON**](https://github.com/omochi/FineJSON) libraries for YAML and JSON respectively. Also keep in mind that JSON is entirely valid YAML and therefore you will likely get good results from Yams decoding of JSON as well (it just won't _encode_ as valid JSON).
80+
81+
The Foundation JSON encoding and decoding will be the most stable and battle-tested option with Yams as a pretty well established and stable option as well. FineJSON is lesser used (to my knowledge) but I have had success with it in the past.
8082

8183
### OpenAPI Document structure
8284
The types used by this library largely mirror the object definitions found in the [OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md) version 3.0.3. The [Project Status](#project-status) lists each object defined by the spec and the name of the respective type in this library.

Tests/OpenAPIKitTests/Operation/OperationTests.swift

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -320,24 +320,17 @@ extension OperationTests {
320320
]
321321
)
322322

323-
let encodedOperation = String(
324-
data: try orderStableEncode(operation),
325-
encoding: .utf8
326-
)!
323+
let encodedOperation = try orderStableYAMLEncode(operation)
327324

328325
XCTAssertEqual(
329326
encodedOperation,
330327
"""
331-
{
332-
"responses": {
333-
"404": {
334-
"$ref": "#/components/responses/404"
335-
},
336-
"200": {
337-
"$ref": "#/components/responses/200"
338-
}
339-
}
340-
}
328+
responses:
329+
404:
330+
$ref: '#/components/responses/404'
331+
200:
332+
$ref: '#/components/responses/200'
333+
341334
"""
342335
)
343336

@@ -348,24 +341,17 @@ extension OperationTests {
348341
]
349342
)
350343

351-
let encodedOperation2 = String(
352-
data: try orderStableEncode(operation2),
353-
encoding: .utf8
354-
)!
344+
let encodedOperation2 = try orderStableYAMLEncode(operation2)
355345

356346
XCTAssertEqual(
357347
encodedOperation2,
358348
"""
359-
{
360-
"responses": {
361-
"200": {
362-
"$ref": "#/components/responses/200"
363-
},
364-
"404": {
365-
"$ref": "#/components/responses/404"
366-
}
367-
}
368-
}
349+
responses:
350+
200:
351+
$ref: '#/components/responses/200'
352+
404:
353+
$ref: '#/components/responses/404'
354+
369355
"""
370356
)
371357
}

Tests/OpenAPIKitTests/TestHelpers.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
import Foundation
9-
import FineJSON
9+
import Yams
1010
import XCTest
1111

1212
fileprivate let foundationTestEncoder = { () -> JSONEncoder in
@@ -32,12 +32,12 @@ func orderUnstableTestStringFromEncoding<T: Encodable>(of entity: T) throws -> S
3232
return String(data: try orderUnstableEncode(entity), encoding: .utf8)
3333
}
3434

35-
fileprivate let fineJSONTestEncoder = { () -> FineJSONEncoder in
36-
return FineJSONEncoder()
35+
fileprivate let yamsTestEncoder = { () -> YAMLEncoder in
36+
return YAMLEncoder()
3737
}()
3838

39-
func orderStableEncode<T: Encodable>(_ value: T) throws -> Data {
40-
return try fineJSONTestEncoder.encode(value)
39+
func orderStableYAMLEncode<T: Encodable>(_ value: T) throws -> String {
40+
return try yamsTestEncoder.encode(value)
4141
}
4242

4343
fileprivate let foundationTestDecoder = { () -> JSONDecoder in
@@ -57,12 +57,12 @@ func orderUnstableDecode<T: Decodable>(_ type: T.Type, from data: Data) throws -
5757
return try foundationTestDecoder.decode(T.self, from: data)
5858
}
5959

60-
fileprivate let fineJSONTestDecoder = { () -> FineJSONDecoder in
61-
return FineJSONDecoder()
60+
fileprivate let yamsTestDecoder = { () -> YAMLDecoder in
61+
return YAMLDecoder()
6262
}()
6363

6464
func orderStableDecode<T: Decodable>(_ type: T.Type, from data: Data) throws -> T {
65-
return try fineJSONTestDecoder.decode(T.self, from: data)
65+
return try yamsTestDecoder.decode(T.self, from: data)
6666
}
6767

6868
func assertJSONEquivalent(_ str1: String?, _ str2: String?, file: StaticString = #file, line: UInt = #line) {

0 commit comments

Comments
 (0)