Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions Sources/OpenAPIKit/Document/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,20 +474,22 @@ extension OpenAPI.Document {
case v3_1_x(x: Int)

case v3_2_0
case v3_2_1
case v3_2_x(x: Int)

// Generally it makes sense for new documents to default to the latest
// released version OpenAPIKit supports but to be safe we will avoid
// the "breaking change" of the default version changing other than
// with major releases.
public static let defaultVersion = Self.v3_2_0
public static let defaultVersion = Self.v3_2_1

public init?(rawValue: String) {
switch rawValue {
case "3.1.0": self = .v3_1_0
case "3.1.1": self = .v3_1_1
case "3.1.2": self = .v3_1_2
case "3.2.0": self = .v3_2_0
case "3.2.1": self = .v3_2_1
default:
let components = rawValue.split(separator: ".")
guard components.count == 3 else {
Expand All @@ -506,7 +508,7 @@ extension OpenAPI.Document {
let v3_1PatchUpperBound = 2
let v3_2PatchUpperBound = 1
if minorVersion == "2" {
guard patchVersion > 0 && patchVersion <= v3_2PatchUpperBound else {
guard patchVersion > 1 && patchVersion <= v3_2PatchUpperBound else {
return nil
}
self = .v3_2_x(x: patchVersion)
Expand All @@ -527,6 +529,7 @@ extension OpenAPI.Document {
case .v3_1_x(x: let x): return "3.1.\(x)"

case .v3_2_0: return "3.2.0"
case .v3_2_1: return "3.2.1"
case .v3_2_x(x: let x): return "3.2.\(x)"
}
}
Expand All @@ -540,6 +543,7 @@ extension OpenAPI.Document {
case .v3_1_2: true
case .v3_1_x(x: let x): 0 < x
case .v3_2_0: true
case .v3_2_1: true
case .v3_2_x(x: _): true
}

Expand All @@ -550,6 +554,7 @@ extension OpenAPI.Document {
case .v3_1_2: true
case .v3_1_x(x: let y): 1 < y
case .v3_2_0: true
case .v3_2_1: true
case .v3_2_x(x: _): true
}

Expand All @@ -560,6 +565,7 @@ extension OpenAPI.Document {
case .v3_1_2: false
case .v3_1_x(x: let y): 2 < y
case .v3_2_0: true
case .v3_2_1: true
case .v3_2_x(x: _): true
}

Expand All @@ -570,6 +576,7 @@ extension OpenAPI.Document {
case .v3_1_2: x < 2
case .v3_1_x(x: let y): x < y
case .v3_2_0: true
case .v3_2_1: true
case .v3_2_x(x: _): true
}

Expand All @@ -580,16 +587,29 @@ extension OpenAPI.Document {
case .v3_1_2: false
case .v3_1_x(x: _): false
case .v3_2_0: false
case .v3_2_1: true
case .v3_2_x(x: let y): 0 < y
}

case .v3_2_1:
switch rhs {
case .v3_1_0: false
case .v3_1_1: false
case .v3_1_2: false
case .v3_1_x(x: _): false
case .v3_2_0: false
case .v3_2_1: false
case .v3_2_x(x: let y): 1 < y
}

case .v3_2_x(x: let x):
switch rhs {
case .v3_1_0: false
case .v3_1_1: false
case .v3_1_2: false
case .v3_1_x(x: _): false
case .v3_2_0: x < 0
case .v3_2_1: x < 1
case .v3_2_x(x: let y): x < y
}
}
Expand Down
72 changes: 38 additions & 34 deletions Tests/OpenAPIKitTests/Document/DocumentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,23 @@ final class DocumentTests: XCTestCase {
let t5 = OpenAPI.Document.Version.v3_2_0
XCTAssertEqual(t5.rawValue, "3.2.0")

let t6 = OpenAPI.Document.Version(rawValue: "3.1.0")
XCTAssertEqual(t6, .v3_1_0)
let t6 = OpenAPI.Document.Version.v3_2_1
XCTAssertEqual(t6.rawValue, "3.2.1")

let t7 = OpenAPI.Document.Version(rawValue: "3.1.1")
XCTAssertEqual(t7, .v3_1_1)
let t16 = OpenAPI.Document.Version(rawValue: "3.1.0")
XCTAssertEqual(t16, .v3_1_0)

let t8 = OpenAPI.Document.Version(rawValue: "3.1.2")
XCTAssertEqual(t8, .v3_1_2)
let t17 = OpenAPI.Document.Version(rawValue: "3.1.1")
XCTAssertEqual(t17, .v3_1_1)

let t9 = OpenAPI.Document.Version(rawValue: "3.2.0")
XCTAssertEqual(t9, .v3_2_0)
let t18 = OpenAPI.Document.Version(rawValue: "3.1.2")
XCTAssertEqual(t18, .v3_1_2)

let t10 = OpenAPI.Document.Version(rawValue: "3.2.1")
XCTAssertEqual(t10, .v3_2_x(x: 1))
let t19 = OpenAPI.Document.Version(rawValue: "3.2.0")
XCTAssertEqual(t19, .v3_2_0)

let t20 = OpenAPI.Document.Version(rawValue: "3.2.1")
XCTAssertEqual(t20, .v3_2_1)

// not a known version:
let ta = OpenAPI.Document.Version(rawValue: "3.1.8")
Expand All @@ -99,7 +102,8 @@ final class DocumentTests: XCTestCase {
.v3_1_0,
.v3_1_1,
.v3_1_2,
.v3_2_0
.v3_2_0,
.v3_2_1
]

for v1Idx in 0...(versions.count - 2) {
Expand Down Expand Up @@ -539,7 +543,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0"
"openapi" : "3.2.1"
}
"""
)
Expand All @@ -553,7 +557,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"paths" : {

}
Expand Down Expand Up @@ -703,7 +707,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"servers" : [
{
"url" : "http:\\/\\/google.com"
Expand All @@ -722,7 +726,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"paths" : {

},
Expand Down Expand Up @@ -765,7 +769,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0"
"openapi" : "3.2.1"
}
"""
)
Expand All @@ -780,7 +784,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"paths" : {

}
Expand Down Expand Up @@ -817,7 +821,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"paths" : {
"\\/test" : {
"summary" : "hi"
Expand All @@ -836,7 +840,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"paths" : {
"\\/test" : {
"summary" : "hi"
Expand Down Expand Up @@ -889,7 +893,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"security" : [
{
"security" : [
Expand Down Expand Up @@ -924,7 +928,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"paths" : {

},
Expand Down Expand Up @@ -963,7 +967,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"paths" : {

},
Expand Down Expand Up @@ -1052,7 +1056,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"paths" : {

},
Expand Down Expand Up @@ -1088,7 +1092,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"tags" : [
{
"name" : "hi"
Expand All @@ -1107,7 +1111,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"paths" : {

},
Expand Down Expand Up @@ -1153,7 +1157,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0"
"openapi" : "3.2.1"
}
"""
)
Expand All @@ -1170,7 +1174,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"paths" : {

}
Expand Down Expand Up @@ -1212,7 +1216,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"x-specialFeature" : [
"hello",
"world"
Expand All @@ -1233,7 +1237,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"paths" : {

},
Expand Down Expand Up @@ -1273,7 +1277,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"paths" : {

},
Expand Down Expand Up @@ -1325,7 +1329,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"webhooks" : {
"webhook-test" : {
"delete" : {
Expand Down Expand Up @@ -1396,7 +1400,7 @@ extension DocumentTests {
"title": "API",
"version": "1.0"
},
"openapi": "3.2.0",
"openapi": "3.2.1",
"paths": {
},
"webhooks": {
Expand Down Expand Up @@ -1468,7 +1472,7 @@ extension DocumentTests {
"title" : "API",
"version" : "1.0"
},
"openapi" : "3.2.0",
"openapi" : "3.2.1",
"webhooks" : {
"webhook-test" : {
"delete" : {
Expand Down Expand Up @@ -1517,7 +1521,7 @@ extension DocumentTests {
"title": "API",
"version": "1.0"
},
"openapi": "3.2.0",
"openapi": "3.2.1",
"webhooks": {
"webhook-test": {
"delete": {
Expand Down