Skip to content

Commit d79dc9d

Browse files
authored
Merge pull request #2736 from hey-api/copilot/fix-2110710e-8174-470d-8162-ec3f601f9ba9
2 parents c7f3d53 + 078face commit d79dc9d

File tree

27 files changed

+656
-60
lines changed

27 files changed

+656
-60
lines changed

.changeset/mighty-paws-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
fix(zod): allOf in array items being generated as union instead of intersection
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
openapi: 3.0.2
2+
info:
3+
title: OpenAPI 3.0.2 array items allOf example
4+
version: '1'
5+
components:
6+
schemas:
7+
# Test case 1: Array with allOf of object schemas
8+
ArrayWithAllOfObjects:
9+
type: array
10+
items:
11+
allOf:
12+
- type: object
13+
properties:
14+
id:
15+
type: integer
16+
- type: object
17+
properties:
18+
name:
19+
type: string
20+
# Test case 2: Array with allOf of primitives
21+
ArrayWithAllOfPrimitives:
22+
type: array
23+
items:
24+
allOf:
25+
- type: number
26+
- type: string
27+
# Test case 3: Array with allOf including refs
28+
ArrayWithAllOfRefs:
29+
type: array
30+
items:
31+
allOf:
32+
- $ref: '#/components/schemas/BaseModel'
33+
- type: object
34+
properties:
35+
extra:
36+
type: string
37+
BaseModel:
38+
type: object
39+
properties:
40+
id:
41+
type: integer
42+
createdAt:
43+
type: string
44+
format: date-time
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
openapi: 3.1.0
2+
info:
3+
title: OpenAPI 3.1.0 array items allOf example
4+
version: '1'
5+
components:
6+
schemas:
7+
# Test case 1: Array with allOf of object schemas
8+
ArrayWithAllOfObjects:
9+
type: array
10+
items:
11+
allOf:
12+
- type: object
13+
properties:
14+
id:
15+
type: integer
16+
- type: object
17+
properties:
18+
name:
19+
type: string
20+
# Test case 2: Array with allOf of primitives
21+
ArrayWithAllOfPrimitives:
22+
type: array
23+
items:
24+
allOf:
25+
- type: number
26+
- type: string
27+
# Test case 3: Array with allOf including refs
28+
ArrayWithAllOfRefs:
29+
type: array
30+
items:
31+
allOf:
32+
- $ref: '#/components/schemas/BaseModel'
33+
- type: object
34+
properties:
35+
extra:
36+
type: string
37+
BaseModel:
38+
type: object
39+
properties:
40+
id:
41+
type: integer
42+
createdAt:
43+
type: string
44+
format: date-time
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import * as z from 'zod/v4-mini';
4+
5+
export const zArrayWithAllOfObjects = z.array(z.intersection(z.object({
6+
id: z.optional(z.int())
7+
}), z.object({
8+
name: z.optional(z.string())
9+
})));
10+
11+
export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));
12+
13+
export const zBaseModel = z.object({
14+
id: z.optional(z.int()),
15+
createdAt: z.optional(z.iso.datetime())
16+
});
17+
18+
export const zArrayWithAllOfRefs = z.array(z.intersection(zBaseModel, z.object({
19+
extra: z.optional(z.string())
20+
})));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { z } from 'zod';
4+
5+
export const zArrayWithAllOfObjects = z.array(z.object({
6+
id: z.number().int().optional()
7+
}).and(z.object({
8+
name: z.string().optional()
9+
})));
10+
11+
export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));
12+
13+
export const zBaseModel = z.object({
14+
id: z.number().int().optional(),
15+
createdAt: z.string().datetime().optional()
16+
});
17+
18+
export const zArrayWithAllOfRefs = z.array(zBaseModel.and(z.object({
19+
extra: z.string().optional()
20+
})));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { z } from 'zod/v4';
4+
5+
export const zArrayWithAllOfObjects = z.array(z.object({
6+
id: z.optional(z.int())
7+
}).and(z.object({
8+
name: z.optional(z.string())
9+
})));
10+
11+
export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));
12+
13+
export const zBaseModel = z.object({
14+
id: z.optional(z.int()),
15+
createdAt: z.optional(z.iso.datetime())
16+
});
17+
18+
export const zArrayWithAllOfRefs = z.array(zBaseModel.and(z.object({
19+
extra: z.optional(z.string())
20+
})));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import * as z from 'zod/v4-mini';
4+
5+
export const zArrayWithAllOfObjects = z.array(z.intersection(z.object({
6+
id: z.optional(z.int())
7+
}), z.object({
8+
name: z.optional(z.string())
9+
})));
10+
11+
export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));
12+
13+
export const zBaseModel = z.object({
14+
id: z.optional(z.int()),
15+
createdAt: z.optional(z.iso.datetime())
16+
});
17+
18+
export const zArrayWithAllOfRefs = z.array(z.intersection(zBaseModel, z.object({
19+
extra: z.optional(z.string())
20+
})));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { z } from 'zod';
4+
5+
export const zArrayWithAllOfObjects = z.array(z.object({
6+
id: z.number().int().optional()
7+
}).and(z.object({
8+
name: z.string().optional()
9+
})));
10+
11+
export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));
12+
13+
export const zBaseModel = z.object({
14+
id: z.number().int().optional(),
15+
createdAt: z.string().datetime().optional()
16+
});
17+
18+
export const zArrayWithAllOfRefs = z.array(zBaseModel.and(z.object({
19+
extra: z.string().optional()
20+
})));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { z } from 'zod/v4';
4+
5+
export const zArrayWithAllOfObjects = z.array(z.object({
6+
id: z.optional(z.int())
7+
}).and(z.object({
8+
name: z.optional(z.string())
9+
})));
10+
11+
export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));
12+
13+
export const zBaseModel = z.object({
14+
id: z.optional(z.int()),
15+
createdAt: z.optional(z.iso.datetime())
16+
});
17+
18+
export const zArrayWithAllOfRefs = z.array(zBaseModel.and(z.object({
19+
extra: z.optional(z.string())
20+
})));

0 commit comments

Comments
 (0)