@@ -4085,6 +4085,12 @@ extension SchemaObjectTests {
4085
4085
] ,
4086
4086
discriminator: . init( propertyName: " hello " )
4087
4087
)
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
+ )
4088
4094
4089
4095
testEncodingPropertyLines (
4090
4096
entity: oneOf,
@@ -4136,6 +4142,25 @@ extension SchemaObjectTests {
4136
4142
" ] "
4137
4143
]
4138
4144
)
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
+ )
4139
4164
}
4140
4165
4141
4166
func test_decodeOne( ) throws {
@@ -4158,8 +4183,18 @@ extension SchemaObjectTests {
4158
4183
}
4159
4184
""" . data ( using: . utf8) !
4160
4185
4186
+ let oneWithReferenceData = """
4187
+ {
4188
+ " oneOf " : [
4189
+ { " type " : " object " },
4190
+ { " $ref " : " #/components/schemas/test " }
4191
+ ]
4192
+ }
4193
+ """ . data ( using: . utf8) !
4194
+
4161
4195
let one = try orderUnstableDecode ( JSONSchema . self, from: oneData)
4162
4196
let oneWithDiscriminator = try orderUnstableDecode ( JSONSchema . self, from: oneWithDiscriminatorData)
4197
+ let oneWithReference = try orderUnstableDecode ( JSONSchema . self, from: oneWithReferenceData)
4163
4198
4164
4199
XCTAssertEqual (
4165
4200
one,
@@ -4181,6 +4216,16 @@ extension SchemaObjectTests {
4181
4216
discriminator: . init( propertyName: " hello " )
4182
4217
)
4183
4218
)
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
+ )
4184
4229
}
4185
4230
4186
4231
func test_encodeAny( ) {
@@ -4199,6 +4244,13 @@ extension SchemaObjectTests {
4199
4244
discriminator: . init( propertyName: " hello " )
4200
4245
)
4201
4246
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
+
4202
4254
testEncodingPropertyLines (
4203
4255
entity: anyOf,
4204
4256
propertyLines: [
@@ -4249,6 +4301,25 @@ extension SchemaObjectTests {
4249
4301
" } "
4250
4302
]
4251
4303
)
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
+ )
4252
4323
}
4253
4324
4254
4325
func test_decodeAny( ) throws {
@@ -4271,8 +4342,18 @@ extension SchemaObjectTests {
4271
4342
}
4272
4343
""" . data ( using: . utf8) !
4273
4344
4345
+ let anyWithReferenceData = """
4346
+ {
4347
+ " anyOf " : [
4348
+ { " type " : " boolean " },
4349
+ { " $ref " : " #/components/schemas/test " }
4350
+ ]
4351
+ }
4352
+ """ . data ( using: . utf8) !
4353
+
4274
4354
let any = try orderUnstableDecode ( JSONSchema . self, from: anyData)
4275
4355
let anyWithDiscriminator = try orderUnstableDecode ( JSONSchema . self, from: anyWithDiscriminatorData)
4356
+ let anyWithReference = try orderUnstableDecode ( JSONSchema . self, from: anyWithReferenceData)
4276
4357
4277
4358
XCTAssertEqual (
4278
4359
any,
@@ -4294,6 +4375,16 @@ extension SchemaObjectTests {
4294
4375
discriminator: . init( propertyName: " hello " )
4295
4376
)
4296
4377
)
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
+ )
4297
4388
}
4298
4389
4299
4390
func test_encodeNot( ) {
0 commit comments