File tree Expand file tree Collapse file tree 15 files changed +145
-239
lines changed
2.0.x/v3/array-items-all-of
3.0.x/v3/array-items-all-of
3.1.x/v3/array-items-all-of
2.0.x/v3/array-items-all-of
3.0.x/v3/array-items-all-of
3.1.x/v3/array-items-all-of
openapi-ts/src/plugins/zod/v3 Expand file tree Collapse file tree 15 files changed +145
-239
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ swagger : ' 2.0'
2
+ info :
3
+ title : OpenAPI 2.0 array items allOf example
4
+ version : ' 1'
5
+ definitions :
6
+ ArrayWithAllOfObjects :
7
+ type : array
8
+ items :
9
+ allOf :
10
+ - type : object
11
+ properties :
12
+ id :
13
+ type : integer
14
+ - type : object
15
+ properties :
16
+ name :
17
+ type : string
18
+ ArrayWithAllOfPrimitives :
19
+ type : array
20
+ items :
21
+ allOf :
22
+ - type : number
23
+ - type : string
24
+ ArrayWithAllOfRefs :
25
+ type : array
26
+ items :
27
+ allOf :
28
+ - $ref : ' #/definitions/BaseModel'
29
+ - type : object
30
+ properties :
31
+ extra :
32
+ type : string
33
+ BaseModel :
34
+ type : object
35
+ properties :
36
+ id :
37
+ type : integer
38
+ createdAt :
39
+ type : string
40
+ format : date-time
Original file line number Diff line number Diff line change 2
2
3
3
import { z } from 'zod' ;
4
4
5
- export const zArrayWithAllOfObjects = z . array ( z . union ( [
6
- z . object ( {
7
- id : z . number ( ) . int ( ) . optional ( )
8
- } ) ,
9
- z . object ( {
10
- name : z . string ( ) . optional ( )
11
- } )
12
- ] ) ) ;
5
+ export const zArrayWithAllOfObjects = z . array ( z . object ( {
6
+ id : z . number ( ) . int ( ) . optional ( )
7
+ } ) . and ( z . object ( {
8
+ name : z . string ( ) . optional ( )
9
+ } ) ) ) ;
13
10
14
- export const zArrayWithAllOfPrimitives = z . array ( z . union ( [
15
- z . number ( ) ,
16
- z . string ( )
17
- ] ) ) ;
11
+ export const zArrayWithAllOfPrimitives = z . array ( z . intersection ( z . number ( ) , z . string ( ) ) ) ;
18
12
19
13
export const zBaseModel = z . object ( {
20
14
id : z . number ( ) . int ( ) . optional ( ) ,
21
15
createdAt : z . string ( ) . datetime ( ) . optional ( )
22
16
} ) ;
23
17
24
- export const zArrayWithAllOfRefs = z . array ( z . union ( [
25
- zBaseModel ,
26
- z . object ( {
27
- extra : z . string ( ) . optional ( )
28
- } )
29
- ] ) ) ;
18
+ export const zArrayWithAllOfRefs = z . array ( zBaseModel . and ( z . object ( {
19
+ extra : z . string ( ) . optional ( )
20
+ } ) ) ) ;
Original file line number Diff line number Diff line change 2
2
3
3
import { z } from 'zod' ;
4
4
5
- export const zArrayWithAllOfObjects = z . array ( z . union ( [
6
- z . object ( {
7
- id : z . number ( ) . int ( ) . optional ( )
8
- } ) ,
9
- z . object ( {
10
- name : z . string ( ) . optional ( )
11
- } )
12
- ] ) ) ;
5
+ export const zArrayWithAllOfObjects = z . array ( z . object ( {
6
+ id : z . number ( ) . int ( ) . optional ( )
7
+ } ) . and ( z . object ( {
8
+ name : z . string ( ) . optional ( )
9
+ } ) ) ) ;
13
10
14
- export const zArrayWithAllOfPrimitives = z . array ( z . union ( [
15
- z . number ( ) ,
16
- z . string ( )
17
- ] ) ) ;
11
+ export const zArrayWithAllOfPrimitives = z . array ( z . intersection ( z . number ( ) , z . string ( ) ) ) ;
18
12
19
13
export const zBaseModel = z . object ( {
20
14
id : z . number ( ) . int ( ) . optional ( ) ,
21
15
createdAt : z . string ( ) . datetime ( ) . optional ( )
22
16
} ) ;
23
17
24
- export const zArrayWithAllOfRefs = z . array ( z . union ( [
25
- zBaseModel ,
26
- z . object ( {
27
- extra : z . string ( ) . optional ( )
28
- } )
29
- ] ) ) ;
18
+ export const zArrayWithAllOfRefs = z . array ( zBaseModel . and ( z . object ( {
19
+ extra : z . string ( ) . optional ( )
20
+ } ) ) ) ;
Original file line number Diff line number Diff line change 2
2
3
3
import { z } from 'zod' ;
4
4
5
- export const zArrayWithAllOfObjects = z . array ( z . union ( [
6
- z . object ( {
7
- id : z . number ( ) . int ( ) . optional ( )
8
- } ) ,
9
- z . object ( {
10
- name : z . string ( ) . optional ( )
11
- } )
12
- ] ) ) ;
5
+ export const zArrayWithAllOfObjects = z . array ( z . object ( {
6
+ id : z . number ( ) . int ( ) . optional ( )
7
+ } ) . and ( z . object ( {
8
+ name : z . string ( ) . optional ( )
9
+ } ) ) ) ;
13
10
14
- export const zArrayWithAllOfPrimitives = z . array ( z . union ( [
15
- z . number ( ) ,
16
- z . string ( )
17
- ] ) ) ;
11
+ export const zArrayWithAllOfPrimitives = z . array ( z . intersection ( z . number ( ) , z . string ( ) ) ) ;
18
12
19
13
export const zBaseModel = z . object ( {
20
14
id : z . number ( ) . int ( ) . optional ( ) ,
21
15
createdAt : z . string ( ) . datetime ( ) . optional ( )
22
16
} ) ;
23
17
24
- export const zArrayWithAllOfRefs = z . array ( z . union ( [
25
- zBaseModel ,
26
- z . object ( {
27
- extra : z . string ( ) . optional ( )
28
- } )
29
- ] ) ) ;
18
+ export const zArrayWithAllOfRefs = z . array ( zBaseModel . and ( z . object ( {
19
+ extra : z . string ( ) . optional ( )
20
+ } ) ) ) ;
Original file line number Diff line number Diff line change @@ -34,14 +34,6 @@ for (const zodVersion of zodVersions) {
34
34
} ) ;
35
35
36
36
const scenarios = [
37
- {
38
- config : createConfig ( {
39
- input : 'array-items-all-of.yaml' ,
40
- output : 'array-items-all-of' ,
41
- } ) ,
42
- description :
43
- 'generates correct array when items use allOf (intersection)' ,
44
- } ,
45
37
{
46
38
config : createConfig ( {
47
39
input : 'array-items-one-of-length-1.yaml' ,
Original file line number Diff line number Diff line change @@ -34,14 +34,6 @@ for (const zodVersion of zodVersions) {
34
34
} ) ;
35
35
36
36
const scenarios = [
37
- {
38
- config : createConfig ( {
39
- input : 'array-items-all-of.yaml' ,
40
- output : 'array-items-all-of' ,
41
- } ) ,
42
- description :
43
- 'generates correct array when items use allOf (intersection)' ,
44
- } ,
45
37
{
46
38
config : createConfig ( {
47
39
input : 'array-items-one-of-length-1.yaml' ,
Original file line number Diff line number Diff line change @@ -37,8 +37,7 @@ for (const version of versions) {
37
37
const scenarios = [
38
38
{
39
39
config : createConfig ( {
40
- input :
41
- 'array-items-all-of.' + ( version === '2.0.x' ? 'json' : 'yaml' ) ,
40
+ input : 'array-items-all-of.yaml' ,
42
41
output : 'array-items-all-of' ,
43
42
} ) ,
44
43
description :
Original file line number Diff line number Diff line change 2
2
3
3
import { z } from 'zod/v3' ;
4
4
5
- export const zArrayWithAllOfObjects = z . array ( z . union ( [
6
- z . object ( {
7
- id : z . number ( ) . int ( ) . optional ( )
8
- } ) ,
9
- z . object ( {
10
- name : z . string ( ) . optional ( )
11
- } )
12
- ] ) ) ;
5
+ export const zArrayWithAllOfObjects = z . array ( z . object ( {
6
+ id : z . number ( ) . int ( ) . optional ( )
7
+ } ) . and ( z . object ( {
8
+ name : z . string ( ) . optional ( )
9
+ } ) ) ) ;
13
10
14
- export const zArrayWithAllOfPrimitives = z . array ( z . union ( [
15
- z . number ( ) ,
16
- z . string ( )
17
- ] ) ) ;
11
+ export const zArrayWithAllOfPrimitives = z . array ( z . intersection ( z . number ( ) , z . string ( ) ) ) ;
18
12
19
13
export const zBaseModel = z . object ( {
20
14
id : z . number ( ) . int ( ) . optional ( ) ,
21
15
createdAt : z . string ( ) . datetime ( ) . optional ( )
22
16
} ) ;
23
17
24
- export const zArrayWithAllOfRefs = z . array ( z . union ( [
25
- zBaseModel ,
26
- z . object ( {
27
- extra : z . string ( ) . optional ( )
28
- } )
29
- ] ) ) ;
18
+ export const zArrayWithAllOfRefs = z . array ( zBaseModel . and ( z . object ( {
19
+ extra : z . string ( ) . optional ( )
20
+ } ) ) ) ;
Original file line number Diff line number Diff line change 2
2
3
3
import { z } from 'zod/v3' ;
4
4
5
- export const zArrayWithAllOfObjects = z . array ( z . union ( [
6
- z . object ( {
7
- id : z . number ( ) . int ( ) . optional ( )
8
- } ) ,
9
- z . object ( {
10
- name : z . string ( ) . optional ( )
11
- } )
12
- ] ) ) ;
5
+ export const zArrayWithAllOfObjects = z . array ( z . object ( {
6
+ id : z . number ( ) . int ( ) . optional ( )
7
+ } ) . and ( z . object ( {
8
+ name : z . string ( ) . optional ( )
9
+ } ) ) ) ;
13
10
14
- export const zArrayWithAllOfPrimitives = z . array ( z . union ( [
15
- z . number ( ) ,
16
- z . string ( )
17
- ] ) ) ;
11
+ export const zArrayWithAllOfPrimitives = z . array ( z . intersection ( z . number ( ) , z . string ( ) ) ) ;
18
12
19
13
export const zBaseModel = z . object ( {
20
14
id : z . number ( ) . int ( ) . optional ( ) ,
21
15
createdAt : z . string ( ) . datetime ( ) . optional ( )
22
16
} ) ;
23
17
24
- export const zArrayWithAllOfRefs = z . array ( z . union ( [
25
- zBaseModel ,
26
- z . object ( {
27
- extra : z . string ( ) . optional ( )
28
- } )
29
- ] ) ) ;
18
+ export const zArrayWithAllOfRefs = z . array ( zBaseModel . and ( z . object ( {
19
+ extra : z . string ( ) . optional ( )
20
+ } ) ) ) ;
You can’t perform that action at this time.
0 commit comments