File tree Expand file tree Collapse file tree 10 files changed +108
-1
lines changed
mini/validators-string-constraints-union
v3/validators-string-constraints-union
v4/validators-string-constraints-union
mini/validators-string-constraints-union
v3/validators-string-constraints-union
v4/validators-string-constraints-union Expand file tree Collapse file tree 10 files changed +108
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ ] ) ;
Original file line number Diff line number Diff line change
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
+ ] ) ;
Original file line number Diff line number Diff line change
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
+ ] ) ;
Original file line number Diff line number Diff line change @@ -138,6 +138,13 @@ for (const zodVersion of zodVersions) {
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 } ) => {
Original file line number Diff line number Diff line change
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
+ ] ) ;
Original file line number Diff line number Diff line change
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
+ ] ) ;
Original file line number Diff line number Diff line change
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
+ ] ) ;
Original file line number Diff line number Diff line change @@ -138,6 +138,13 @@ for (const zodVersion of zodVersions) {
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 } ) => {
Original file line number Diff line number Diff line change @@ -42,7 +42,25 @@ export const deduplicateSchema = <T extends IR.SchemaObject>({
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 ) ;
You can’t perform that action at this time.
0 commit comments