Skip to content

Commit e347c68

Browse files
authored
Merge pull request #101 from mattpolzin/tests/reference-compound-schemas
add more tests around references within the other compound schema types.
2 parents 05bb1f9 + 5ddde9b commit e347c68

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

Tests/OpenAPIKitTests/Schema Object/SchemaObjectTests.swift

+91
Original file line numberDiff line numberDiff line change
@@ -4085,6 +4085,12 @@ extension SchemaObjectTests {
40854085
],
40864086
discriminator: .init(propertyName: "hello")
40874087
)
4088+
let oneOfWithReference = JSONSchema.one(
4089+
of: [
4090+
.object(.init(format: .unspecified, required: true), .init(properties: ["hello": .string(.init(format: .generic, required: false), .init())])),
4091+
.reference(.component(named: "test"))
4092+
]
4093+
)
40884094

40894095
testEncodingPropertyLines(
40904096
entity: oneOf,
@@ -4136,6 +4142,25 @@ extension SchemaObjectTests {
41364142
"]"
41374143
]
41384144
)
4145+
4146+
testEncodingPropertyLines(
4147+
entity: oneOfWithReference,
4148+
propertyLines: [
4149+
"\"oneOf\" : [",
4150+
" {",
4151+
" \"properties\" : {",
4152+
" \"hello\" : {",
4153+
" \"type\" : \"string\"",
4154+
" }",
4155+
" },",
4156+
" \"type\" : \"object\"",
4157+
" },",
4158+
" {",
4159+
" \"$ref\" : \"#\\/components\\/schemas\\/test\"",
4160+
" }",
4161+
"]"
4162+
]
4163+
)
41394164
}
41404165

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

4186+
let oneWithReferenceData = """
4187+
{
4188+
"oneOf": [
4189+
{ "type": "object" },
4190+
{ "$ref": "#/components/schemas/test" }
4191+
]
4192+
}
4193+
""".data(using: .utf8)!
4194+
41614195
let one = try orderUnstableDecode(JSONSchema.self, from: oneData)
41624196
let oneWithDiscriminator = try orderUnstableDecode(JSONSchema.self, from: oneWithDiscriminatorData)
4197+
let oneWithReference = try orderUnstableDecode(JSONSchema.self, from: oneWithReferenceData)
41634198

41644199
XCTAssertEqual(
41654200
one,
@@ -4181,6 +4216,16 @@ extension SchemaObjectTests {
41814216
discriminator: .init(propertyName: "hello")
41824217
)
41834218
)
4219+
4220+
XCTAssertEqual(
4221+
oneWithReference,
4222+
JSONSchema.one(
4223+
of: [
4224+
.object(.init(format: .generic, required: false), .init(properties: [:])),
4225+
.reference(.component(named: "test"))
4226+
]
4227+
)
4228+
)
41844229
}
41854230

41864231
func test_encodeAny() {
@@ -4199,6 +4244,13 @@ extension SchemaObjectTests {
41994244
discriminator: .init(propertyName: "hello")
42004245
)
42014246

4247+
let anyOfWithReference = JSONSchema.any(
4248+
of: [
4249+
.object(.init(format: .unspecified, required: true), .init(properties: ["hello": .string(.init(format: .generic, required: false), .init())])),
4250+
.reference(.component(named: "test"))
4251+
]
4252+
)
4253+
42024254
testEncodingPropertyLines(
42034255
entity: anyOf,
42044256
propertyLines: [
@@ -4249,6 +4301,25 @@ extension SchemaObjectTests {
42494301
"}"
42504302
]
42514303
)
4304+
4305+
testEncodingPropertyLines(
4306+
entity: anyOfWithReference,
4307+
propertyLines: [
4308+
"\"anyOf\" : [",
4309+
" {",
4310+
" \"properties\" : {",
4311+
" \"hello\" : {",
4312+
" \"type\" : \"string\"",
4313+
" }",
4314+
" },",
4315+
" \"type\" : \"object\"",
4316+
" },",
4317+
" {",
4318+
" \"$ref\" : \"#\\/components\\/schemas\\/test\"",
4319+
" }",
4320+
"]"
4321+
]
4322+
)
42524323
}
42534324

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

4345+
let anyWithReferenceData = """
4346+
{
4347+
"anyOf": [
4348+
{ "type": "boolean" },
4349+
{ "$ref": "#/components/schemas/test" }
4350+
]
4351+
}
4352+
""".data(using: .utf8)!
4353+
42744354
let any = try orderUnstableDecode(JSONSchema.self, from: anyData)
42754355
let anyWithDiscriminator = try orderUnstableDecode(JSONSchema.self, from: anyWithDiscriminatorData)
4356+
let anyWithReference = try orderUnstableDecode(JSONSchema.self, from: anyWithReferenceData)
42764357

42774358
XCTAssertEqual(
42784359
any,
@@ -4294,6 +4375,16 @@ extension SchemaObjectTests {
42944375
discriminator: .init(propertyName: "hello")
42954376
)
42964377
)
4378+
4379+
XCTAssertEqual(
4380+
anyWithReference,
4381+
JSONSchema.any(
4382+
of: [
4383+
.boolean(.init(format: .generic, required: false)),
4384+
.reference(.component(named: "test"))
4385+
]
4386+
)
4387+
)
42974388
}
42984389

42994390
func test_encodeNot() {

0 commit comments

Comments
 (0)