Skip to content

Commit c7c7b8b

Browse files
committed
test cases
1 parent ace1ef3 commit c7c7b8b

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

Tests/OpenAPIKit30Tests/Document/DocumentTests.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,33 @@ extension DocumentTests {
511511
)
512512
}
513513

514+
func test_specifyUknownOpenAPIVersion_encode() throws {
515+
let document = OpenAPI.Document(
516+
openAPIVersion: .v3_0_x(x: 9),
517+
info: .init(title: "API", version: "1.0"),
518+
servers: [],
519+
paths: [:],
520+
components: .noComponents
521+
)
522+
let encodedDocument = try orderUnstableTestStringFromEncoding(of: document)
523+
524+
assertJSONEquivalent(
525+
encodedDocument,
526+
"""
527+
{
528+
"info" : {
529+
"title" : "API",
530+
"version" : "1.0"
531+
},
532+
"openapi" : "3.0.9",
533+
"paths" : {
534+
535+
}
536+
}
537+
"""
538+
)
539+
}
540+
514541
func test_specifyOpenAPIVersion_decode() throws {
515542
let documentData =
516543
"""
@@ -539,6 +566,23 @@ extension DocumentTests {
539566
)
540567
}
541568

569+
func test_specifyUnknownOpenAPIVersion_decode() throws {
570+
let documentData =
571+
"""
572+
{
573+
"info" : {
574+
"title" : "API",
575+
"version" : "1.0"
576+
},
577+
"openapi" : "3.0.9",
578+
"paths" : {
579+
580+
}
581+
}
582+
""".data(using: .utf8)!
583+
XCTAssertThrowsError(try orderUnstableDecode(OpenAPI.Document.self, from: documentData)) { error in XCTAssertEqual(OpenAPI.Error(from: error).localizedDescription, "Inconsistency encountered when parsing `openapi` in the root Document object: Cannot initialize Version from invalid String value 3.0.9.") }
584+
}
585+
542586
func test_specifyServers_encode() throws {
543587
let document = OpenAPI.Document(
544588
info: .init(title: "API", version: "1.0"),

Tests/OpenAPIKitTests/Document/DocumentTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,30 @@ extension DocumentTests {
513513
)
514514
}
515515

516+
func test_specifyUknownOpenAPIVersion_encode() throws {
517+
let document = OpenAPI.Document(
518+
openAPIVersion: .v3_1_x(x: 9),
519+
info: .init(title: "API", version: "1.0"),
520+
servers: [],
521+
paths: [:],
522+
components: .noComponents
523+
)
524+
let encodedDocument = try orderUnstableTestStringFromEncoding(of: document)
525+
526+
assertJSONEquivalent(
527+
encodedDocument,
528+
"""
529+
{
530+
"info" : {
531+
"title" : "API",
532+
"version" : "1.0"
533+
},
534+
"openapi" : "3.1.9"
535+
}
536+
"""
537+
)
538+
}
539+
516540
func test_specifyOpenAPIVersion_decode() throws {
517541
let documentData =
518542
"""
@@ -541,6 +565,23 @@ extension DocumentTests {
541565
)
542566
}
543567

568+
func test_specifyUnknownOpenAPIVersion_decode() throws {
569+
let documentData =
570+
"""
571+
{
572+
"info" : {
573+
"title" : "API",
574+
"version" : "1.0"
575+
},
576+
"openapi" : "3.1.9",
577+
"paths" : {
578+
579+
}
580+
}
581+
""".data(using: .utf8)!
582+
XCTAssertThrowsError(try orderUnstableDecode(OpenAPI.Document.self, from: documentData)) { error in XCTAssertEqual(OpenAPI.Error(from: error).localizedDescription, "Inconsistency encountered when parsing `openapi` in the root Document object: Cannot initialize Version from invalid String value 3.1.9.") }
583+
}
584+
544585
func test_specifyServers_encode() throws {
545586
let document = OpenAPI.Document(
546587
info: .init(title: "API", version: "1.0"),

0 commit comments

Comments
 (0)