Skip to content

Commit 7e78118

Browse files
Copilotmrlubos
andcommitted
Address review feedback: fix v3 plugin, remove duplicate tests, use YAML for all specs
Co-authored-by: mrlubos <[email protected]>
1 parent 2b414dc commit 7e78118

File tree

15 files changed

+145
-239
lines changed

15 files changed

+145
-239
lines changed

packages/openapi-ts-tests/specs/2.0.x/array-items-all-of.json

Lines changed: 0 additions & 75 deletions
This file was deleted.
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

packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/array-items-all-of/zod.gen.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,19 @@
22

33
import { z } from 'zod';
44

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+
})));
1310

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()));
1812

1913
export const zBaseModel = z.object({
2014
id: z.number().int().optional(),
2115
createdAt: z.string().datetime().optional()
2216
});
2317

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+
})));

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/array-items-all-of/zod.gen.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,19 @@
22

33
import { z } from 'zod';
44

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+
})));
1310

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()));
1812

1913
export const zBaseModel = z.object({
2014
id: z.number().int().optional(),
2115
createdAt: z.string().datetime().optional()
2216
});
2317

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+
})));

packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/array-items-all-of/zod.gen.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,19 @@
22

33
import { z } from 'zod';
44

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+
})));
1310

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()));
1812

1913
export const zBaseModel = z.object({
2014
id: z.number().int().optional(),
2115
createdAt: z.string().datetime().optional()
2216
});
2317

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+
})));

packages/openapi-ts-tests/zod/v3/test/3.0.x.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ for (const zodVersion of zodVersions) {
3434
});
3535

3636
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-
},
4537
{
4638
config: createConfig({
4739
input: 'array-items-one-of-length-1.yaml',

packages/openapi-ts-tests/zod/v3/test/3.1.x.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ for (const zodVersion of zodVersions) {
3434
});
3535

3636
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-
},
4537
{
4638
config: createConfig({
4739
input: 'array-items-one-of-length-1.yaml',

packages/openapi-ts-tests/zod/v3/test/openapi.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ for (const version of versions) {
3737
const scenarios = [
3838
{
3939
config: createConfig({
40-
input:
41-
'array-items-all-of.' + (version === '2.0.x' ? 'json' : 'yaml'),
40+
input: 'array-items-all-of.yaml',
4241
output: 'array-items-all-of',
4342
}),
4443
description:

packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/array-items-all-of/zod.gen.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,19 @@
22

33
import { z } from 'zod/v3';
44

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+
})));
1310

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()));
1812

1913
export const zBaseModel = z.object({
2014
id: z.number().int().optional(),
2115
createdAt: z.string().datetime().optional()
2216
});
2317

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+
})));

packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/array-items-all-of/zod.gen.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,19 @@
22

33
import { z } from 'zod/v3';
44

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+
})));
1310

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()));
1812

1913
export const zBaseModel = z.object({
2014
id: z.number().int().optional(),
2115
createdAt: z.string().datetime().optional()
2216
});
2317

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+
})));

0 commit comments

Comments
 (0)