Skip to content

Commit 18ae2a2

Browse files
authored
Merge pull request mattpolzin#198 from mattpolzin/remove-fine-json-requirement
Remove FineJSON test requirement
2 parents 6ba1be3 + 92698e1 commit 18ae2a2

File tree

8 files changed

+92
-311
lines changed

8 files changed

+92
-311
lines changed

.github/workflows/tests.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ jobs:
3131
uses: actions/checkout@v2
3232
- name: Run tests
3333
run: swift test --enable-test-discovery
34+
linux-5_4-plus:
35+
runs-on: ubuntu-latest
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
image:
40+
- swift:5.4-xenial
41+
- swift:5.4-bionic
42+
- swift:5.4-focal
43+
- swift:5.4-centos8
44+
- swift:5.4-amazonlinux2
45+
container: ${{ matrix.image }}
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v2
49+
- name: Run tests (without test discovery flag)
50+
run: swift test -Xswiftc -Xfrontend -Xswiftc -sil-verify-none
3451
osx:
3552
runs-on: macOS-latest
3653
steps:

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
@@ -77,7 +77,9 @@ You can use this same validation system to dig arbitrarily deep into an OpenAPI
7777
### A note on dictionary ordering
7878
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.
7979

80-
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.
80+
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).
81+
82+
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.
8183

8284
### OpenAPI Document structure
8385
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/OpenAPIKitCompatibilitySuite/GitHubAPITests.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,15 @@ final class GitHubAPICampatibilityTests: XCTestCase {
2222

2323
override func setUp() {
2424
/*
25-
NOTE: As of GitHub's OpenAPI documentation v 2.22, they started to nest
26-
their schema components in a bit of an unusual way. not clear to me that
27-
the thing they are doing is disallowed by the spec, but definitely weird.
28-
29-
At any rate, it fails here for now so I will pin this to version 2.21 and
30-
revisit later.
25+
NOTE: As of 2/17/2021 the latest released version of GitHub's API documentation
26+
does not pass but the latest commit does; I will pin this test to that
27+
commit for now.
3128
*/
3229
if githubAPI == nil {
3330
githubAPI = Result {
3431
try YAMLDecoder().decode(
3532
OpenAPI.Document.self,
36-
from: String(contentsOf: URL(string: "https://raw.githubusercontent.com/github/rest-api-description/v1.0.0-rc.1/descriptions/ghes-2.21/ghes-2.21.yaml")!)
33+
from: String(contentsOf: URL(string: "https://raw.githubusercontent.com/github/rest-api-description/e4f28959fbc6c9fc4eea823b495061dded87e84d/descriptions/ghes-3.0/ghes-3.0.yaml")!)
3734
)
3835
}
3936
}
@@ -69,8 +66,8 @@ final class GitHubAPICampatibilityTests: XCTestCase {
6966
// contact name is Support
7067
XCTAssertEqual(apiDoc.info.contact?.name, "Support")
7168

72-
// contact URL was parsed as https://support.github.com
73-
XCTAssertEqual(apiDoc.info.contact?.url, URL(string: "https://support.github.com")!)
69+
// contact URL was parsed as https://support.github.com/contact
70+
XCTAssertEqual(apiDoc.info.contact?.url, URL(string: "https://support.github.com/contact")!)
7471

7572
// no contact email is provided
7673
XCTAssert(apiDoc.info.contact?.email?.isEmpty ?? true)
@@ -149,6 +146,6 @@ final class GitHubAPICampatibilityTests: XCTestCase {
149146
let resolvedDoc = try apiDoc.locallyDereferenced().resolved()
150147

151148
XCTAssertEqual(resolvedDoc.routes.count, apiDoc.paths.count)
152-
XCTAssertEqual(resolvedDoc.endpoints.count, 550)
149+
XCTAssertEqual(resolvedDoc.endpoints.count, 664)
153150
}
154151
}

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)