Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-paws-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

fix(zod): allOf in array items being generated as union instead of intersection
40 changes: 40 additions & 0 deletions packages/openapi-ts-tests/specs/2.0.x/array-items-all-of.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
swagger: '2.0'
info:
title: OpenAPI 2.0 array items allOf example
version: '1'
definitions:
ArrayWithAllOfObjects:
type: array
items:
allOf:
- type: object
properties:
id:
type: integer
- type: object
properties:
name:
type: string
ArrayWithAllOfPrimitives:
type: array
items:
allOf:
- type: number
- type: string
ArrayWithAllOfRefs:
type: array
items:
allOf:
- $ref: '#/definitions/BaseModel'
- type: object
properties:
extra:
type: string
BaseModel:
type: object
properties:
id:
type: integer
createdAt:
type: string
format: date-time
44 changes: 44 additions & 0 deletions packages/openapi-ts-tests/specs/3.0.x/array-items-all-of.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
openapi: 3.0.2
info:
title: OpenAPI 3.0.2 array items allOf example
version: '1'
components:
schemas:
# Test case 1: Array with allOf of object schemas
ArrayWithAllOfObjects:
type: array
items:
allOf:
- type: object
properties:
id:
type: integer
- type: object
properties:
name:
type: string
# Test case 2: Array with allOf of primitives
ArrayWithAllOfPrimitives:
type: array
items:
allOf:
- type: number
- type: string
# Test case 3: Array with allOf including refs
ArrayWithAllOfRefs:
type: array
items:
allOf:
- $ref: '#/components/schemas/BaseModel'
- type: object
properties:
extra:
type: string
BaseModel:
type: object
properties:
id:
type: integer
createdAt:
type: string
format: date-time
44 changes: 44 additions & 0 deletions packages/openapi-ts-tests/specs/3.1.x/array-items-all-of.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
openapi: 3.1.0
info:
title: OpenAPI 3.1.0 array items allOf example
version: '1'
components:
schemas:
# Test case 1: Array with allOf of object schemas
ArrayWithAllOfObjects:
type: array
items:
allOf:
- type: object
properties:
id:
type: integer
- type: object
properties:
name:
type: string
# Test case 2: Array with allOf of primitives
ArrayWithAllOfPrimitives:
type: array
items:
allOf:
- type: number
- type: string
# Test case 3: Array with allOf including refs
ArrayWithAllOfRefs:
type: array
items:
allOf:
- $ref: '#/components/schemas/BaseModel'
- type: object
properties:
extra:
type: string
BaseModel:
type: object
properties:
id:
type: integer
createdAt:
type: string
format: date-time
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is auto-generated by @hey-api/openapi-ts

import * as z from 'zod/v4-mini';

export const zArrayWithAllOfObjects = z.array(z.intersection(z.object({
id: z.optional(z.int())
}), z.object({
name: z.optional(z.string())
})));

export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));

export const zBaseModel = z.object({
id: z.optional(z.int()),
createdAt: z.optional(z.iso.datetime())
});

export const zArrayWithAllOfRefs = z.array(z.intersection(zBaseModel, z.object({
extra: z.optional(z.string())
})));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is auto-generated by @hey-api/openapi-ts

import { z } from 'zod';

export const zArrayWithAllOfObjects = z.array(z.object({
id: z.number().int().optional()
}).and(z.object({
name: z.string().optional()
})));

export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));

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

export const zArrayWithAllOfRefs = z.array(zBaseModel.and(z.object({
extra: z.string().optional()
})));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is auto-generated by @hey-api/openapi-ts

import { z } from 'zod/v4';

export const zArrayWithAllOfObjects = z.array(z.object({
id: z.optional(z.int())
}).and(z.object({
name: z.optional(z.string())
})));

export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));

export const zBaseModel = z.object({
id: z.optional(z.int()),
createdAt: z.optional(z.iso.datetime())
});

export const zArrayWithAllOfRefs = z.array(zBaseModel.and(z.object({
extra: z.optional(z.string())
})));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is auto-generated by @hey-api/openapi-ts

import * as z from 'zod/v4-mini';

export const zArrayWithAllOfObjects = z.array(z.intersection(z.object({
id: z.optional(z.int())
}), z.object({
name: z.optional(z.string())
})));

export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));

export const zBaseModel = z.object({
id: z.optional(z.int()),
createdAt: z.optional(z.iso.datetime())
});

export const zArrayWithAllOfRefs = z.array(z.intersection(zBaseModel, z.object({
extra: z.optional(z.string())
})));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is auto-generated by @hey-api/openapi-ts

import { z } from 'zod';

export const zArrayWithAllOfObjects = z.array(z.object({
id: z.number().int().optional()
}).and(z.object({
name: z.string().optional()
})));

export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));

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

export const zArrayWithAllOfRefs = z.array(zBaseModel.and(z.object({
extra: z.string().optional()
})));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is auto-generated by @hey-api/openapi-ts

import { z } from 'zod/v4';

export const zArrayWithAllOfObjects = z.array(z.object({
id: z.optional(z.int())
}).and(z.object({
name: z.optional(z.string())
})));

export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));

export const zBaseModel = z.object({
id: z.optional(z.int()),
createdAt: z.optional(z.iso.datetime())
});

export const zArrayWithAllOfRefs = z.array(zBaseModel.and(z.object({
extra: z.optional(z.string())
})));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is auto-generated by @hey-api/openapi-ts

import * as z from 'zod/v4-mini';

export const zArrayWithAllOfObjects = z.array(z.intersection(z.object({
id: z.optional(z.int())
}), z.object({
name: z.optional(z.string())
})));

export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));

export const zBaseModel = z.object({
id: z.optional(z.int()),
createdAt: z.optional(z.iso.datetime())
});

export const zArrayWithAllOfRefs = z.array(z.intersection(zBaseModel, z.object({
extra: z.optional(z.string())
})));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is auto-generated by @hey-api/openapi-ts

import { z } from 'zod';

export const zArrayWithAllOfObjects = z.array(z.object({
id: z.number().int().optional()
}).and(z.object({
name: z.string().optional()
})));

export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));

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

export const zArrayWithAllOfRefs = z.array(zBaseModel.and(z.object({
extra: z.string().optional()
})));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is auto-generated by @hey-api/openapi-ts

import { z } from 'zod/v4';

export const zArrayWithAllOfObjects = z.array(z.object({
id: z.optional(z.int())
}).and(z.object({
name: z.optional(z.string())
})));

export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));

export const zBaseModel = z.object({
id: z.optional(z.int()),
createdAt: z.optional(z.iso.datetime())
});

export const zArrayWithAllOfRefs = z.array(zBaseModel.and(z.object({
extra: z.optional(z.string())
})));
8 changes: 8 additions & 0 deletions packages/openapi-ts-tests/zod/v3/test/openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ for (const version of versions) {
});

const scenarios = [
{
config: createConfig({
input: 'array-items-all-of.yaml',
output: 'array-items-all-of',
}),
description:
'generates correct array when items use allOf (intersection)',
},
{
config: createConfig({
input: 'full.yaml',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is auto-generated by @hey-api/openapi-ts

import * as z from 'zod/mini';

export const zArrayWithAllOfObjects = z.array(z.intersection(z.object({
id: z.optional(z.int())
}), z.object({
name: z.optional(z.string())
})));

export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));

export const zBaseModel = z.object({
id: z.optional(z.int()),
createdAt: z.optional(z.iso.datetime())
});

export const zArrayWithAllOfRefs = z.array(z.intersection(zBaseModel, z.object({
extra: z.optional(z.string())
})));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is auto-generated by @hey-api/openapi-ts

import { z } from 'zod/v3';

export const zArrayWithAllOfObjects = z.array(z.object({
id: z.number().int().optional()
}).and(z.object({
name: z.string().optional()
})));

export const zArrayWithAllOfPrimitives = z.array(z.intersection(z.number(), z.string()));

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

export const zArrayWithAllOfRefs = z.array(zBaseModel.and(z.object({
extra: z.string().optional()
})));
Loading
Loading