@@ -299,6 +299,59 @@ describe("composition", () => {
299
299
} ,
300
300
} ,
301
301
] ,
302
+ [
303
+ // this is actually invalid syntax for oneOfs, but we support it anyways for better compatibility with bad schemas
304
+ "discriminator > oneOf inside object" ,
305
+ {
306
+ given : {
307
+ type : "object" ,
308
+ required : [ "name" ] ,
309
+ properties : {
310
+ name : { type : "string" } ,
311
+ } ,
312
+ oneOf : [
313
+ { $ref : "#/components/schemas/Cat" } ,
314
+ { $ref : "#/components/schemas/Dog" } ,
315
+ ] ,
316
+ } ,
317
+ want : `{
318
+ name: string;
319
+ } & (components["schemas"]["Cat"] | components["schemas"]["Dog"])` ,
320
+ options : {
321
+ path : "#/components/schemas/Pet" ,
322
+ ctx : {
323
+ ...DEFAULT_OPTIONS . ctx ,
324
+ discriminators : {
325
+ objects : {
326
+ "#/components/schemas/Pet" : {
327
+ propertyName : "petType" ,
328
+ } ,
329
+ "#/components/schemas/Cat" : {
330
+ propertyName : "petType" ,
331
+ } ,
332
+ "#/components/schemas/Dog" : {
333
+ propertyName : "petType" ,
334
+ } ,
335
+ } ,
336
+ refsHandled : [ ] ,
337
+ } ,
338
+ resolve ( $ref ) {
339
+ switch ( $ref ) {
340
+ case "#/components/schemas/Pet" : {
341
+ return {
342
+ propertyName : "petType" ,
343
+ oneOf : [ "#/components/schemas/Cat" ] ,
344
+ } ;
345
+ }
346
+ default : {
347
+ return undefined as any ;
348
+ }
349
+ }
350
+ } ,
351
+ } ,
352
+ } ,
353
+ } ,
354
+ ] ,
302
355
[
303
356
"discriminator > oneOf + null + implicit mapping" ,
304
357
{
0 commit comments