Skip to content

Commit

Permalink
Merge pull request #101 from mattpolzin/tests/reference-compound-schemas
Browse files Browse the repository at this point in the history
add more tests around references within the other compound schema types.
  • Loading branch information
mattpolzin authored Jul 28, 2020
2 parents 05bb1f9 + 5ddde9b commit e347c68
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions Tests/OpenAPIKitTests/Schema Object/SchemaObjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4085,6 +4085,12 @@ extension SchemaObjectTests {
],
discriminator: .init(propertyName: "hello")
)
let oneOfWithReference = JSONSchema.one(
of: [
.object(.init(format: .unspecified, required: true), .init(properties: ["hello": .string(.init(format: .generic, required: false), .init())])),
.reference(.component(named: "test"))
]
)

testEncodingPropertyLines(
entity: oneOf,
Expand Down Expand Up @@ -4136,6 +4142,25 @@ extension SchemaObjectTests {
"]"
]
)

testEncodingPropertyLines(
entity: oneOfWithReference,
propertyLines: [
"\"oneOf\" : [",
" {",
" \"properties\" : {",
" \"hello\" : {",
" \"type\" : \"string\"",
" }",
" },",
" \"type\" : \"object\"",
" },",
" {",
" \"$ref\" : \"#\\/components\\/schemas\\/test\"",
" }",
"]"
]
)
}

func test_decodeOne() throws {
Expand All @@ -4158,8 +4183,18 @@ extension SchemaObjectTests {
}
""".data(using: .utf8)!

let oneWithReferenceData = """
{
"oneOf": [
{ "type": "object" },
{ "$ref": "#/components/schemas/test" }
]
}
""".data(using: .utf8)!

let one = try orderUnstableDecode(JSONSchema.self, from: oneData)
let oneWithDiscriminator = try orderUnstableDecode(JSONSchema.self, from: oneWithDiscriminatorData)
let oneWithReference = try orderUnstableDecode(JSONSchema.self, from: oneWithReferenceData)

XCTAssertEqual(
one,
Expand All @@ -4181,6 +4216,16 @@ extension SchemaObjectTests {
discriminator: .init(propertyName: "hello")
)
)

XCTAssertEqual(
oneWithReference,
JSONSchema.one(
of: [
.object(.init(format: .generic, required: false), .init(properties: [:])),
.reference(.component(named: "test"))
]
)
)
}

func test_encodeAny() {
Expand All @@ -4199,6 +4244,13 @@ extension SchemaObjectTests {
discriminator: .init(propertyName: "hello")
)

let anyOfWithReference = JSONSchema.any(
of: [
.object(.init(format: .unspecified, required: true), .init(properties: ["hello": .string(.init(format: .generic, required: false), .init())])),
.reference(.component(named: "test"))
]
)

testEncodingPropertyLines(
entity: anyOf,
propertyLines: [
Expand Down Expand Up @@ -4249,6 +4301,25 @@ extension SchemaObjectTests {
"}"
]
)

testEncodingPropertyLines(
entity: anyOfWithReference,
propertyLines: [
"\"anyOf\" : [",
" {",
" \"properties\" : {",
" \"hello\" : {",
" \"type\" : \"string\"",
" }",
" },",
" \"type\" : \"object\"",
" },",
" {",
" \"$ref\" : \"#\\/components\\/schemas\\/test\"",
" }",
"]"
]
)
}

func test_decodeAny() throws {
Expand All @@ -4271,8 +4342,18 @@ extension SchemaObjectTests {
}
""".data(using: .utf8)!

let anyWithReferenceData = """
{
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#/components/schemas/test" }
]
}
""".data(using: .utf8)!

let any = try orderUnstableDecode(JSONSchema.self, from: anyData)
let anyWithDiscriminator = try orderUnstableDecode(JSONSchema.self, from: anyWithDiscriminatorData)
let anyWithReference = try orderUnstableDecode(JSONSchema.self, from: anyWithReferenceData)

XCTAssertEqual(
any,
Expand All @@ -4294,6 +4375,16 @@ extension SchemaObjectTests {
discriminator: .init(propertyName: "hello")
)
)

XCTAssertEqual(
anyWithReference,
JSONSchema.any(
of: [
.boolean(.init(format: .generic, required: false)),
.reference(.component(named: "test"))
]
)
)
}

func test_encodeNot() {
Expand Down

0 comments on commit e347c68

Please sign in to comment.