File tree Expand file tree Collapse file tree
openapi-ts/src/plugins/zod Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -423,13 +423,9 @@ export const zModelSquare = z.object({
423423/**
424424 * This is a model with one property with a 'one of' relationship where the options are not $ref
425425 */
426- export const zCompositionWithOneOfDiscriminator = z . union ( [
427- z . intersection ( z . object ( {
428- kind : z . literal ( 'circle' )
429- } ) , zModelCircle ) ,
430- z . intersection ( z . object ( {
431- kind : z . literal ( 'square' )
432- } ) , zModelSquare )
426+ export const zCompositionWithOneOfDiscriminator = z . discriminatedUnion ( 'kind' , [
427+ zModelCircle . extend ( { kind : z . literal ( 'circle' ) } ) ,
428+ zModelSquare . extend ( { kind : z . literal ( 'square' ) } )
433429] ) ;
434430
435431/**
Original file line number Diff line number Diff line change @@ -423,13 +423,9 @@ export const zModelSquare = z.object({
423423/**
424424 * This is a model with one property with a 'one of' relationship where the options are not $ref
425425 */
426- export const zCompositionWithOneOfDiscriminator = z . union ( [
427- z . intersection ( z . object ( {
428- kind : z . literal ( 'circle' )
429- } ) , zModelCircle ) ,
430- z . intersection ( z . object ( {
431- kind : z . literal ( 'square' )
432- } ) , zModelSquare )
426+ export const zCompositionWithOneOfDiscriminator = z . discriminatedUnion ( 'kind' , [
427+ zModelCircle . extend ( { kind : z . literal ( 'circle' ) } ) ,
428+ zModelSquare . extend ( { kind : z . literal ( 'square' ) } )
433429] ) ;
434430
435431/**
Original file line number Diff line number Diff line change @@ -50,13 +50,9 @@ export const zBazUnion = z.object({
5050 baz : z . optional ( z . string ( ) )
5151} ) ;
5252
53- export const zFooUnion = z . union ( [
54- z . intersection ( z . object ( {
55- id : z . literal ( 'bar' )
56- } ) , zBarUnion ) ,
57- z . intersection ( z . object ( {
58- id : z . literal ( 'baz' )
59- } ) , zBazUnion )
53+ export const zFooUnion = z . discriminatedUnion ( 'id' , [
54+ zBarUnion . extend ( { id : z . literal ( 'bar' ) } ) ,
55+ zBazUnion . extend ( { id : z . literal ( 'baz' ) } )
6056] ) ;
6157
6258export const zQuxExtend = zFooUnion ;
Original file line number Diff line number Diff line change @@ -13,25 +13,15 @@ export const zBaz = zQux;
1313
1414export const zBar = zQux ;
1515
16- export const zFoo = z . union ( [
17- z . intersection ( z . object ( {
18- type : z . optional ( z . literal ( 'Bar' ) )
19- } ) , zBar ) ,
20- z . intersection ( z . object ( {
21- type : z . optional ( z . literal ( 'Baz' ) )
22- } ) , zBaz )
16+ export const zFoo = z . discriminatedUnion ( 'type' , [
17+ zBar . extend ( { type : z . literal ( 'Bar' ) } ) ,
18+ zBaz . extend ( { type : z . literal ( 'Baz' ) } )
2319] ) ;
2420
2521export const zSpæcial = zQux ;
2622
27- export const zQuuz = z . union ( [
28- z . intersection ( z . object ( {
29- type : z . optional ( z . literal ( 'bar' ) )
30- } ) , zBar ) ,
31- z . intersection ( z . object ( {
32- type : z . optional ( z . literal ( 'baz' ) )
33- } ) , zBaz ) ,
34- z . intersection ( z . object ( {
35- type : z . optional ( z . literal ( 'non-ascii' ) )
36- } ) , zSpæcial )
23+ export const zQuuz = z . discriminatedUnion ( 'type' , [
24+ zBar . extend ( { type : z . literal ( 'bar' ) } ) ,
25+ zBaz . extend ( { type : z . literal ( 'baz' ) } ) ,
26+ zSpæcial . extend ( { type : z . literal ( 'non-ascii' ) } )
3727] ) ;
Original file line number Diff line number Diff line change @@ -13,25 +13,15 @@ export const zBaz = zQux;
1313
1414export const zBar = zQux ;
1515
16- export const zFoo = z . union ( [
17- z . intersection ( z . object ( {
18- type : z . literal ( 'Bar' )
19- } ) , zBar ) ,
20- z . intersection ( z . object ( {
21- type : z . literal ( 'Baz' )
22- } ) , zBaz )
16+ export const zFoo = z . discriminatedUnion ( 'type' , [
17+ zBar . extend ( { type : z . literal ( 'Bar' ) } ) ,
18+ zBaz . extend ( { type : z . literal ( 'Baz' ) } )
2319] ) ;
2420
2521export const zSpæcial = zQux ;
2622
27- export const zQuuz = z . union ( [
28- z . intersection ( z . object ( {
29- type : z . literal ( 'bar' )
30- } ) , zBar ) ,
31- z . intersection ( z . object ( {
32- type : z . literal ( 'baz' )
33- } ) , zBaz ) ,
34- z . intersection ( z . object ( {
35- type : z . literal ( 'non-ascii' )
36- } ) , zSpæcial )
23+ export const zQuuz = z . discriminatedUnion ( 'type' , [
24+ zBar . extend ( { type : z . literal ( 'bar' ) } ) ,
25+ zBaz . extend ( { type : z . literal ( 'baz' ) } ) ,
26+ zSpæcial . extend ( { type : z . literal ( 'non-ascii' ) } )
3727] ) ;
Original file line number Diff line number Diff line change @@ -423,13 +423,9 @@ export const zModelSquare = z.object({
423423/**
424424 * This is a model with one property with a 'one of' relationship where the options are not $ref
425425 */
426- export const zCompositionWithOneOfDiscriminator = z . union ( [
427- z . intersection ( z . object ( {
428- kind : z . literal ( 'circle' )
429- } ) , zModelCircle ) ,
430- z . intersection ( z . object ( {
431- kind : z . literal ( 'square' )
432- } ) , zModelSquare )
426+ export const zCompositionWithOneOfDiscriminator = z . discriminatedUnion ( 'kind' , [
427+ zModelCircle . extend ( { kind : z . literal ( 'circle' ) } ) ,
428+ zModelSquare . extend ( { kind : z . literal ( 'square' ) } )
433429] ) ;
434430
435431/**
Original file line number Diff line number Diff line change @@ -423,13 +423,9 @@ export const zModelSquare = z.object({
423423/**
424424 * This is a model with one property with a 'one of' relationship where the options are not $ref
425425 */
426- export const zCompositionWithOneOfDiscriminator = z . union ( [
427- z . intersection ( z . object ( {
428- kind : z . literal ( 'circle' )
429- } ) , zModelCircle ) ,
430- z . intersection ( z . object ( {
431- kind : z . literal ( 'square' )
432- } ) , zModelSquare )
426+ export const zCompositionWithOneOfDiscriminator = z . discriminatedUnion ( 'kind' , [
427+ zModelCircle . extend ( { kind : z . literal ( 'circle' ) } ) ,
428+ zModelSquare . extend ( { kind : z . literal ( 'square' ) } )
433429] ) ;
434430
435431/**
Original file line number Diff line number Diff line change @@ -50,13 +50,9 @@ export const zBazUnion = z.object({
5050 baz : z . optional ( z . string ( ) )
5151} ) ;
5252
53- export const zFooUnion = z . union ( [
54- z . intersection ( z . object ( {
55- id : z . literal ( 'bar' )
56- } ) , zBarUnion ) ,
57- z . intersection ( z . object ( {
58- id : z . literal ( 'baz' )
59- } ) , zBazUnion )
53+ export const zFooUnion = z . discriminatedUnion ( 'id' , [
54+ zBarUnion . extend ( { id : z . literal ( 'bar' ) } ) ,
55+ zBazUnion . extend ( { id : z . literal ( 'baz' ) } )
6056] ) ;
6157
6258export const zQuxExtend = zFooUnion ;
Original file line number Diff line number Diff line change @@ -13,25 +13,15 @@ export const zBaz = zQux;
1313
1414export const zBar = zQux ;
1515
16- export const zFoo = z . union ( [
17- z . intersection ( z . object ( {
18- type : z . optional ( z . literal ( 'Bar' ) )
19- } ) , zBar ) ,
20- z . intersection ( z . object ( {
21- type : z . optional ( z . literal ( 'Baz' ) )
22- } ) , zBaz )
16+ export const zFoo = z . discriminatedUnion ( 'type' , [
17+ zBar . extend ( { type : z . literal ( 'Bar' ) } ) ,
18+ zBaz . extend ( { type : z . literal ( 'Baz' ) } )
2319] ) ;
2420
2521export const zSpæcial = zQux ;
2622
27- export const zQuuz = z . union ( [
28- z . intersection ( z . object ( {
29- type : z . optional ( z . literal ( 'bar' ) )
30- } ) , zBar ) ,
31- z . intersection ( z . object ( {
32- type : z . optional ( z . literal ( 'baz' ) )
33- } ) , zBaz ) ,
34- z . intersection ( z . object ( {
35- type : z . optional ( z . literal ( 'non-ascii' ) )
36- } ) , zSpæcial )
23+ export const zQuuz = z . discriminatedUnion ( 'type' , [
24+ zBar . extend ( { type : z . literal ( 'bar' ) } ) ,
25+ zBaz . extend ( { type : z . literal ( 'baz' ) } ) ,
26+ zSpæcial . extend ( { type : z . literal ( 'non-ascii' ) } )
3727] ) ;
Original file line number Diff line number Diff line change @@ -13,25 +13,15 @@ export const zBaz = zQux;
1313
1414export const zBar = zQux ;
1515
16- export const zFoo = z . union ( [
17- z . intersection ( z . object ( {
18- type : z . literal ( 'Bar' )
19- } ) , zBar ) ,
20- z . intersection ( z . object ( {
21- type : z . literal ( 'Baz' )
22- } ) , zBaz )
16+ export const zFoo = z . discriminatedUnion ( 'type' , [
17+ zBar . extend ( { type : z . literal ( 'Bar' ) } ) ,
18+ zBaz . extend ( { type : z . literal ( 'Baz' ) } )
2319] ) ;
2420
2521export const zSpæcial = zQux ;
2622
27- export const zQuuz = z . union ( [
28- z . intersection ( z . object ( {
29- type : z . literal ( 'bar' )
30- } ) , zBar ) ,
31- z . intersection ( z . object ( {
32- type : z . literal ( 'baz' )
33- } ) , zBaz ) ,
34- z . intersection ( z . object ( {
35- type : z . literal ( 'non-ascii' )
36- } ) , zSpæcial )
23+ export const zQuuz = z . discriminatedUnion ( 'type' , [
24+ zBar . extend ( { type : z . literal ( 'bar' ) } ) ,
25+ zBaz . extend ( { type : z . literal ( 'baz' ) } ) ,
26+ zSpæcial . extend ( { type : z . literal ( 'non-ascii' ) } )
3727] ) ;
You can’t perform that action at this time.
0 commit comments