fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add comprehensive snapshot tests for allOf in array items across all Zod versions

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>

+628 -1
+75
packages/openapi-ts-tests/specs/2.0.x/array-items-all-of.json
··· 1 + { 2 + "swagger": "2.0", 3 + "info": { 4 + "title": "OpenAPI 2.0 array items allOf example", 5 + "version": "1" 6 + }, 7 + "definitions": { 8 + "ArrayWithAllOfObjects": { 9 + "type": "array", 10 + "items": { 11 + "allOf": [ 12 + { 13 + "type": "object", 14 + "properties": { 15 + "id": { 16 + "type": "integer" 17 + } 18 + } 19 + }, 20 + { 21 + "type": "object", 22 + "properties": { 23 + "name": { 24 + "type": "string" 25 + } 26 + } 27 + } 28 + ] 29 + } 30 + }, 31 + "ArrayWithAllOfPrimitives": { 32 + "type": "array", 33 + "items": { 34 + "allOf": [ 35 + { 36 + "type": "number" 37 + }, 38 + { 39 + "type": "string" 40 + } 41 + ] 42 + } 43 + }, 44 + "ArrayWithAllOfRefs": { 45 + "type": "array", 46 + "items": { 47 + "allOf": [ 48 + { 49 + "$ref": "#/definitions/BaseModel" 50 + }, 51 + { 52 + "type": "object", 53 + "properties": { 54 + "extra": { 55 + "type": "string" 56 + } 57 + } 58 + } 59 + ] 60 + } 61 + }, 62 + "BaseModel": { 63 + "type": "object", 64 + "properties": { 65 + "id": { 66 + "type": "integer" 67 + }, 68 + "createdAt": { 69 + "type": "string", 70 + "format": "date-time" 71 + } 72 + } 73 + } 74 + } 75 + }
+44
packages/openapi-ts-tests/specs/3.0.x/array-items-all-of.yaml
··· 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
+44
packages/openapi-ts-tests/specs/3.1.x/array-items-all-of.yaml
··· 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
+20
packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/array-items-all-of/zod.gen.ts
··· 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 + })));
+29
packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/array-items-all-of/zod.gen.ts
··· 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.union([ 6 + z.object({ 7 + id: z.number().int().optional() 8 + }), 9 + z.object({ 10 + name: z.string().optional() 11 + }) 12 + ])); 13 + 14 + export const zArrayWithAllOfPrimitives = z.array(z.union([ 15 + z.number(), 16 + z.string() 17 + ])); 18 + 19 + export const zBaseModel = z.object({ 20 + id: z.number().int().optional(), 21 + createdAt: z.string().datetime().optional() 22 + }); 23 + 24 + export const zArrayWithAllOfRefs = z.array(z.union([ 25 + zBaseModel, 26 + z.object({ 27 + extra: z.string().optional() 28 + }) 29 + ]));
+20
packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/array-items-all-of/zod.gen.ts
··· 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 + })));
+20
packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/array-items-all-of/zod.gen.ts
··· 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 + })));
+29
packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/array-items-all-of/zod.gen.ts
··· 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.union([ 6 + z.object({ 7 + id: z.number().int().optional() 8 + }), 9 + z.object({ 10 + name: z.string().optional() 11 + }) 12 + ])); 13 + 14 + export const zArrayWithAllOfPrimitives = z.array(z.union([ 15 + z.number(), 16 + z.string() 17 + ])); 18 + 19 + export const zBaseModel = z.object({ 20 + id: z.number().int().optional(), 21 + createdAt: z.string().datetime().optional() 22 + }); 23 + 24 + export const zArrayWithAllOfRefs = z.array(z.union([ 25 + zBaseModel, 26 + z.object({ 27 + extra: z.string().optional() 28 + }) 29 + ]));
+20
packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/array-items-all-of/zod.gen.ts
··· 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 + })));
+20
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/array-items-all-of/zod.gen.ts
··· 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 + })));
+29
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/array-items-all-of/zod.gen.ts
··· 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.union([ 6 + z.object({ 7 + id: z.number().int().optional() 8 + }), 9 + z.object({ 10 + name: z.string().optional() 11 + }) 12 + ])); 13 + 14 + export const zArrayWithAllOfPrimitives = z.array(z.union([ 15 + z.number(), 16 + z.string() 17 + ])); 18 + 19 + export const zBaseModel = z.object({ 20 + id: z.number().int().optional(), 21 + createdAt: z.string().datetime().optional() 22 + }); 23 + 24 + export const zArrayWithAllOfRefs = z.array(z.union([ 25 + zBaseModel, 26 + z.object({ 27 + extra: z.string().optional() 28 + }) 29 + ]));
+20
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/array-items-all-of/zod.gen.ts
··· 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 + })));
+8
packages/openapi-ts-tests/zod/v3/test/3.0.x.test.ts
··· 36 36 const scenarios = [ 37 37 { 38 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 + { 46 + config: createConfig({ 39 47 input: 'array-items-one-of-length-1.yaml', 40 48 output: 'array-items-one-of-length-1', 41 49 }),
+8
packages/openapi-ts-tests/zod/v3/test/3.1.x.test.ts
··· 36 36 const scenarios = [ 37 37 { 38 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 + { 46 + config: createConfig({ 39 47 input: 'array-items-one-of-length-1.yaml', 40 48 output: 'array-items-one-of-length-1', 41 49 }),
+9
packages/openapi-ts-tests/zod/v3/test/openapi.test.ts
··· 37 37 const scenarios = [ 38 38 { 39 39 config: createConfig({ 40 + input: 41 + 'array-items-all-of.' + (version === '2.0.x' ? 'json' : 'yaml'), 42 + output: 'array-items-all-of', 43 + }), 44 + description: 45 + 'generates correct array when items use allOf (intersection)', 46 + }, 47 + { 48 + config: createConfig({ 40 49 input: 'full.yaml', 41 50 output: 'default', 42 51 }),
+20
packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/array-items-all-of/zod.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import * as z from 'zod/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 + })));
+29
packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/array-items-all-of/zod.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import { z } from 'zod/v3'; 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 + ])); 13 + 14 + export const zArrayWithAllOfPrimitives = z.array(z.union([ 15 + z.number(), 16 + z.string() 17 + ])); 18 + 19 + export const zBaseModel = z.object({ 20 + id: z.number().int().optional(), 21 + createdAt: z.string().datetime().optional() 22 + }); 23 + 24 + export const zArrayWithAllOfRefs = z.array(z.union([ 25 + zBaseModel, 26 + z.object({ 27 + extra: z.string().optional() 28 + }) 29 + ]));
+20
packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/array-items-all-of/zod.gen.ts
··· 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.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 + })));
+20
packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/array-items-all-of/zod.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import * as z from 'zod/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 + })));
+29
packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/array-items-all-of/zod.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import { z } from 'zod/v3'; 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 + ])); 13 + 14 + export const zArrayWithAllOfPrimitives = z.array(z.union([ 15 + z.number(), 16 + z.string() 17 + ])); 18 + 19 + export const zBaseModel = z.object({ 20 + id: z.number().int().optional(), 21 + createdAt: z.string().datetime().optional() 22 + }); 23 + 24 + export const zArrayWithAllOfRefs = z.array(z.union([ 25 + zBaseModel, 26 + z.object({ 27 + extra: z.string().optional() 28 + }) 29 + ]));
+20
packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/array-items-all-of/zod.gen.ts
··· 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.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 + })));
+20
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/array-items-all-of/zod.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import * as z from 'zod/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 + })));
+29
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/array-items-all-of/zod.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import { z } from 'zod/v3'; 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 + ])); 13 + 14 + export const zArrayWithAllOfPrimitives = z.array(z.union([ 15 + z.number(), 16 + z.string() 17 + ])); 18 + 19 + export const zBaseModel = z.object({ 20 + id: z.number().int().optional(), 21 + createdAt: z.string().datetime().optional() 22 + }); 23 + 24 + export const zArrayWithAllOfRefs = z.array(z.union([ 25 + zBaseModel, 26 + z.object({ 27 + extra: z.string().optional() 28 + }) 29 + ]));
+20
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/array-items-all-of/zod.gen.ts
··· 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.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 + })));
+8
packages/openapi-ts-tests/zod/v4/test/3.0.x.test.ts
··· 36 36 const scenarios = [ 37 37 { 38 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 + { 46 + config: createConfig({ 39 47 input: 'array-items-one-of-length-1.yaml', 40 48 output: 'array-items-one-of-length-1', 41 49 }),
+8
packages/openapi-ts-tests/zod/v4/test/3.1.x.test.ts
··· 36 36 const scenarios = [ 37 37 { 38 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 + { 46 + config: createConfig({ 39 47 input: 'array-items-one-of-length-1.yaml', 40 48 output: 'array-items-one-of-length-1', 41 49 }),
+9
packages/openapi-ts-tests/zod/v4/test/openapi.test.ts
··· 37 37 const scenarios = [ 38 38 { 39 39 config: createConfig({ 40 + input: 41 + 'array-items-all-of.' + (version === '2.0.x' ? 'json' : 'yaml'), 42 + output: 'array-items-all-of', 43 + }), 44 + description: 45 + 'generates correct array when items use allOf (intersection)', 46 + }, 47 + { 48 + config: createConfig({ 40 49 input: 'full.yaml', 41 50 output: 'default', 42 51 }),
+1 -1
packages/openapi-ts/src/plugins/zod/mini/plugin.ts
··· 90 90 for (let i = 1; i < itemExpressions.length; i++) { 91 91 intersectionExpression = tsc.callExpression({ 92 92 functionName: tsc.propertyAccessExpression({ 93 - expression: intersectionExpression, 93 + expression: zSymbol.placeholder, 94 94 name: identifiers.intersection, 95 95 }), 96 96 parameters: [intersectionExpression, itemExpressions[i]!],