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.

Merge pull request #2650 from hey-api/copilot/fix-2644

authored by

Lubos and committed by
GitHub
10c13de7 91bc2d00

+113 -1
+5
.changeset/fix-zod-union-deduplication.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix(parser): expand schema deduplication by including validation constraints in type ID
+27
packages/openapi-ts-tests/specs/3.1.x/validators-string-constraints-union.json
··· 1 + { 2 + "openapi": "3.1.0", 3 + "info": { 4 + "title": "String Constraints Union Test", 5 + "version": "1.0.0" 6 + }, 7 + "components": { 8 + "schemas": { 9 + "LocaleOrLanguage": { 10 + "anyOf": [ 11 + { 12 + "type": "string", 13 + "minLength": 5, 14 + "maxLength": 5, 15 + "description": "Combination of ISO 639-1 and ISO 3166-1 alpha-2 separated by a hyphen." 16 + }, 17 + { 18 + "type": "string", 19 + "minLength": 2, 20 + "maxLength": 2, 21 + "description": "ISO 639-1 language code." 22 + } 23 + ] 24 + } 25 + } 26 + } 27 + }
+8
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-string-constraints-union/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 zLocaleOrLanguage = z.union([ 6 + z.string().check(z.length(5)), 7 + z.string().check(z.length(2)) 8 + ]);
+8
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-string-constraints-union/zod.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import { z } from 'zod'; 4 + 5 + export const zLocaleOrLanguage = z.union([ 6 + z.string().length(5), 7 + z.string().length(2) 8 + ]);
+8
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-string-constraints-union/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 zLocaleOrLanguage = z.union([ 6 + z.string().length(5), 7 + z.string().length(2) 8 + ]);
+7
packages/openapi-ts-tests/zod/v3/test/3.1.x.test.ts
··· 138 138 description: 139 139 "validator schemas with merged unions (can't use .merge())", 140 140 }, 141 + { 142 + config: createConfig({ 143 + input: 'validators-string-constraints-union.json', 144 + output: 'validators-string-constraints-union', 145 + }), 146 + description: 'validator schemas with string constraints union', 147 + }, 141 148 ]; 142 149 143 150 it.each(scenarios)('$description', async ({ config }) => {
+8
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-string-constraints-union/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 zLocaleOrLanguage = z.union([ 6 + z.string().check(z.length(5)), 7 + z.string().check(z.length(2)) 8 + ]);
+8
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-string-constraints-union/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 zLocaleOrLanguage = z.union([ 6 + z.string().length(5), 7 + z.string().length(2) 8 + ]);
+8
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-string-constraints-union/zod.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import { z } from 'zod'; 4 + 5 + export const zLocaleOrLanguage = z.union([ 6 + z.string().length(5), 7 + z.string().length(2) 8 + ]);
+7
packages/openapi-ts-tests/zod/v4/test/3.1.x.test.ts
··· 138 138 description: 139 139 "validator schemas with merged unions (can't use .merge())", 140 140 }, 141 + { 142 + config: createConfig({ 143 + input: 'validators-string-constraints-union.json', 144 + output: 'validators-string-constraints-union', 145 + }), 146 + description: 'validator schemas with string constraints union', 147 + }, 141 148 ]; 142 149 143 150 it.each(scenarios)('$description', async ({ config }) => {
+19 -1
packages/openapi-ts/src/ir/schema.ts
··· 42 42 item.format !== undefined && detectFormat 43 43 ? `format-${item.format}` 44 44 : ''; 45 - const typeId = `${item.$ref ?? ''}${item.type ?? ''}${constant}${format}`; 45 + 46 + // Include validation constraints in the type ID to avoid incorrect deduplication 47 + const constraints = [ 48 + item.minLength !== undefined ? `minLength-${item.minLength}` : '', 49 + item.maxLength !== undefined ? `maxLength-${item.maxLength}` : '', 50 + item.minimum !== undefined ? `minimum-${item.minimum}` : '', 51 + item.maximum !== undefined ? `maximum-${item.maximum}` : '', 52 + item.exclusiveMinimum !== undefined 53 + ? `exclusiveMinimum-${item.exclusiveMinimum}` 54 + : '', 55 + item.exclusiveMaximum !== undefined 56 + ? `exclusiveMaximum-${item.exclusiveMaximum}` 57 + : '', 58 + item.minItems !== undefined ? `minItems-${item.minItems}` : '', 59 + item.maxItems !== undefined ? `maxItems-${item.maxItems}` : '', 60 + item.pattern !== undefined ? `pattern-${item.pattern}` : '', 61 + ].join(''); 62 + 63 + const typeId = `${item.$ref ?? ''}${item.type ?? ''}${constant}${format}${constraints}`; 46 64 if (!typeIds.includes(typeId)) { 47 65 typeIds.push(typeId); 48 66 uniqueItems.push(item);