Skip to content

Commit 9eb7525

Browse files
committed
Fix pattern escaping in IR parsers and update snapshots
- Call getPattern() in 3.0.x and 3.1.x IR parsers to escape backslashes - Update all Zod v3 and v4 test snapshots with correct regex patterns - Patterns now correctly exclude backslash characters
1 parent dd0b233 commit 9eb7525

File tree

44 files changed

+160
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+160
-158
lines changed

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,10 @@ export const zModelWithPattern = z.object({
733733
name: z.string().check(z.maxLength(255)),
734734
enabled: z.optional(z.readonly(z.boolean())),
735735
modified: z.optional(z.readonly(z.iso.datetime())),
736-
id: z.optional(z.string().check(z.regex(/^\d{2}-\d{3}-\d{4}$/))),
737-
text: z.optional(z.string().check(z.regex(/^\w+$/))),
738-
patternWithSingleQuotes: z.optional(z.string().check(z.regex(/^[a-zA-Z0-9']*$/))),
739-
patternWithNewline: z.optional(z.string().check(z.regex(/aaa\nbbb/))),
736+
id: z.optional(z.string().check(z.regex(/^\\d{2}-\\d{3}-\\d{4}$/))),
737+
text: z.optional(z.string().check(z.regex(/^\\w+$/))),
738+
patternWithSingleQuotes: z.optional(z.string().check(z.regex(/^[a-zA-Z0-9\']*$/))),
739+
patternWithNewline: z.optional(z.string().check(z.regex(/aaa\\nbbb/))),
740740
patternWithBacktick: z.optional(z.string().check(z.regex(/aaa`bbb/)))
741741
});
742742

@@ -1126,10 +1126,10 @@ export const zModelWithPropertiesWritable = z.object({
11261126
export const zModelWithPatternWritable = z.object({
11271127
key: z.string().check(z.maxLength(64), z.regex(/^[a-zA-Z0-9_]*$/)),
11281128
name: z.string().check(z.maxLength(255)),
1129-
id: z.optional(z.string().check(z.regex(/^\d{2}-\d{3}-\d{4}$/))),
1130-
text: z.optional(z.string().check(z.regex(/^\w+$/))),
1131-
patternWithSingleQuotes: z.optional(z.string().check(z.regex(/^[a-zA-Z0-9']*$/))),
1132-
patternWithNewline: z.optional(z.string().check(z.regex(/aaa\nbbb/))),
1129+
id: z.optional(z.string().check(z.regex(/^\\d{2}-\\d{3}-\\d{4}$/))),
1130+
text: z.optional(z.string().check(z.regex(/^\\w+$/))),
1131+
patternWithSingleQuotes: z.optional(z.string().check(z.regex(/^[a-zA-Z0-9\']*$/))),
1132+
patternWithNewline: z.optional(z.string().check(z.regex(/aaa\\nbbb/))),
11331133
patternWithBacktick: z.optional(z.string().check(z.regex(/aaa`bbb/)))
11341134
});
11351135

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const zBar = z.object({
1010

1111
export const zFoo = z._default(z.union([
1212
z.object({
13-
foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))),
13+
foo: z.optional(z.string().check(z.regex(/^\\d{3}-\\d{2}-\\d{4}$/))),
1414
bar: z.optional(zBar),
1515
get baz(): z.ZodMiniOptional {
1616
return z.optional(z.array(z.lazy((): any => {
@@ -22,4 +22,4 @@ export const zFoo = z._default(z.union([
2222
z.null()
2323
]), null);
2424

25-
export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz');
25+
export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\\nbar/))), 'baz');

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,10 @@ export const zModelWithPattern = z.object({
731731
name: z.string().max(255),
732732
enabled: z.boolean().readonly().optional(),
733733
modified: z.string().datetime().readonly().optional(),
734-
id: z.string().regex(/^\d{2}-\d{3}-\d{4}$/).optional(),
735-
text: z.string().regex(/^\w+$/).optional(),
736-
patternWithSingleQuotes: z.string().regex(/^[a-zA-Z0-9']*$/).optional(),
737-
patternWithNewline: z.string().regex(/aaa\nbbb/).optional(),
734+
id: z.string().regex(/^\\d{2}-\\d{3}-\\d{4}$/).optional(),
735+
text: z.string().regex(/^\\w+$/).optional(),
736+
patternWithSingleQuotes: z.string().regex(/^[a-zA-Z0-9\']*$/).optional(),
737+
patternWithNewline: z.string().regex(/aaa\\nbbb/).optional(),
738738
patternWithBacktick: z.string().regex(/aaa`bbb/).optional()
739739
});
740740

@@ -1124,10 +1124,10 @@ export const zModelWithPropertiesWritable = z.object({
11241124
export const zModelWithPatternWritable = z.object({
11251125
key: z.string().max(64).regex(/^[a-zA-Z0-9_]*$/),
11261126
name: z.string().max(255),
1127-
id: z.string().regex(/^\d{2}-\d{3}-\d{4}$/).optional(),
1128-
text: z.string().regex(/^\w+$/).optional(),
1129-
patternWithSingleQuotes: z.string().regex(/^[a-zA-Z0-9']*$/).optional(),
1130-
patternWithNewline: z.string().regex(/aaa\nbbb/).optional(),
1127+
id: z.string().regex(/^\\d{2}-\\d{3}-\\d{4}$/).optional(),
1128+
text: z.string().regex(/^\\w+$/).optional(),
1129+
patternWithSingleQuotes: z.string().regex(/^[a-zA-Z0-9\']*$/).optional(),
1130+
patternWithNewline: z.string().regex(/aaa\\nbbb/).optional(),
11311131
patternWithBacktick: z.string().regex(/aaa`bbb/).optional()
11321132
});
11331133

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const zBar: z.AnyZodObject = z.object({
1010

1111
export const zFoo: z.ZodTypeAny = z.union([
1212
z.object({
13-
foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(),
13+
foo: z.string().regex(/^\\d{3}-\\d{2}-\\d{4}$/).optional(),
1414
bar: zBar.optional(),
1515
baz: z.array(z.lazy(() => {
1616
return zFoo;
@@ -20,4 +20,4 @@ export const zFoo: z.ZodTypeAny = z.union([
2020
z.null()
2121
]).default(null);
2222

23-
export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz');
23+
export const zBaz = z.string().regex(/foo\\nbar/).readonly().default('baz');

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,10 @@ export const zModelWithPattern = z.object({
733733
name: z.string().max(255),
734734
enabled: z.optional(z.boolean().readonly()),
735735
modified: z.optional(z.iso.datetime().readonly()),
736-
id: z.optional(z.string().regex(/^\d{2}-\d{3}-\d{4}$/)),
737-
text: z.optional(z.string().regex(/^\w+$/)),
738-
patternWithSingleQuotes: z.optional(z.string().regex(/^[a-zA-Z0-9']*$/)),
739-
patternWithNewline: z.optional(z.string().regex(/aaa\nbbb/)),
736+
id: z.optional(z.string().regex(/^\\d{2}-\\d{3}-\\d{4}$/)),
737+
text: z.optional(z.string().regex(/^\\w+$/)),
738+
patternWithSingleQuotes: z.optional(z.string().regex(/^[a-zA-Z0-9\']*$/)),
739+
patternWithNewline: z.optional(z.string().regex(/aaa\\nbbb/)),
740740
patternWithBacktick: z.optional(z.string().regex(/aaa`bbb/))
741741
});
742742

@@ -1126,10 +1126,10 @@ export const zModelWithPropertiesWritable = z.object({
11261126
export const zModelWithPatternWritable = z.object({
11271127
key: z.string().max(64).regex(/^[a-zA-Z0-9_]*$/),
11281128
name: z.string().max(255),
1129-
id: z.optional(z.string().regex(/^\d{2}-\d{3}-\d{4}$/)),
1130-
text: z.optional(z.string().regex(/^\w+$/)),
1131-
patternWithSingleQuotes: z.optional(z.string().regex(/^[a-zA-Z0-9']*$/)),
1132-
patternWithNewline: z.optional(z.string().regex(/aaa\nbbb/)),
1129+
id: z.optional(z.string().regex(/^\\d{2}-\\d{3}-\\d{4}$/)),
1130+
text: z.optional(z.string().regex(/^\\w+$/)),
1131+
patternWithSingleQuotes: z.optional(z.string().regex(/^[a-zA-Z0-9\']*$/)),
1132+
patternWithNewline: z.optional(z.string().regex(/aaa\\nbbb/)),
11331133
patternWithBacktick: z.optional(z.string().regex(/aaa`bbb/))
11341134
});
11351135

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const zBar = z.object({
1010

1111
export const zFoo = z.union([
1212
z.object({
13-
foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)),
13+
foo: z.optional(z.string().regex(/^\\d{3}-\\d{2}-\\d{4}$/)),
1414
bar: z.optional(zBar),
1515
get baz(): z.ZodOptional {
1616
return z.optional(z.array(z.lazy((): any => {
@@ -22,4 +22,4 @@ export const zFoo = z.union([
2222
z.null()
2323
]).default(null);
2424

25-
export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz');
25+
export const zBaz = z.string().regex(/foo\\nbar/).readonly().default('baz');

packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -740,10 +740,10 @@ export const zModelWithPattern = z.object({
740740
name: z.string().check(z.maxLength(255)),
741741
enabled: z.optional(z.readonly(z.boolean())),
742742
modified: z.optional(z.readonly(z.iso.datetime())),
743-
id: z.optional(z.string().check(z.regex(/^\d{2}-\d{3}-\d{4}$/))),
744-
text: z.optional(z.string().check(z.regex(/^\w+$/))),
745-
patternWithSingleQuotes: z.optional(z.string().check(z.regex(/^[a-zA-Z0-9']*$/))),
746-
patternWithNewline: z.optional(z.string().check(z.regex(/aaa\nbbb/))),
743+
id: z.optional(z.string().check(z.regex(/^\\d{2}-\\d{3}-\\d{4}$/))),
744+
text: z.optional(z.string().check(z.regex(/^\\w+$/))),
745+
patternWithSingleQuotes: z.optional(z.string().check(z.regex(/^[a-zA-Z0-9\']*$/))),
746+
patternWithNewline: z.optional(z.string().check(z.regex(/aaa\\nbbb/))),
747747
patternWithBacktick: z.optional(z.string().check(z.regex(/aaa`bbb/)))
748748
});
749749

@@ -1132,10 +1132,10 @@ export const zModelWithPropertiesWritable = z.object({
11321132
export const zModelWithPatternWritable = z.object({
11331133
key: z.string().check(z.maxLength(64), z.regex(/^[a-zA-Z0-9_]*$/)),
11341134
name: z.string().check(z.maxLength(255)),
1135-
id: z.optional(z.string().check(z.regex(/^\d{2}-\d{3}-\d{4}$/))),
1136-
text: z.optional(z.string().check(z.regex(/^\w+$/))),
1137-
patternWithSingleQuotes: z.optional(z.string().check(z.regex(/^[a-zA-Z0-9']*$/))),
1138-
patternWithNewline: z.optional(z.string().check(z.regex(/aaa\nbbb/))),
1135+
id: z.optional(z.string().check(z.regex(/^\\d{2}-\\d{3}-\\d{4}$/))),
1136+
text: z.optional(z.string().check(z.regex(/^\\w+$/))),
1137+
patternWithSingleQuotes: z.optional(z.string().check(z.regex(/^[a-zA-Z0-9\']*$/))),
1138+
patternWithNewline: z.optional(z.string().check(z.regex(/aaa\\nbbb/))),
11391139
patternWithBacktick: z.optional(z.string().check(z.regex(/aaa`bbb/)))
11401140
});
11411141

packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const zBar = z.object({
1616
*/
1717
export const zFoo = z._default(z.union([
1818
z.object({
19-
foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))),
19+
foo: z.optional(z.string().check(z.regex(/^\\d{3}-\\d{2}-\\d{4}$/))),
2020
bar: z.optional(zBar),
2121
get baz(): z.ZodMiniOptional {
2222
return z.optional(z.array(z.lazy((): any => {
@@ -28,7 +28,7 @@ export const zFoo = z._default(z.union([
2828
z.null()
2929
]), null);
3030

31-
export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz');
31+
export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\\nbar/))), 'baz');
3232

3333
export const zQux = z.record(z.string(), z.object({
3434
qux: z.optional(z.string())

packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const zBar = z.object({
1818
*/
1919
export const zFoo = z._default(z.union([
2020
z.object({
21-
foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/)).register(z.globalRegistry, {
21+
foo: z.optional(z.string().check(z.regex(/^\\d{3}-\\d{2}-\\d{4}$/)).register(z.globalRegistry, {
2222
description: 'This is foo property.'
2323
})),
2424
bar: z.optional(zBar),
@@ -36,7 +36,7 @@ export const zFoo = z._default(z.union([
3636
z.null()
3737
]), null);
3838

39-
export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz');
39+
export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\\nbar/))), 'baz');
4040

4141
export const zQux = z.record(z.string(), z.object({
4242
qux: z.optional(z.string())

packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type BarZodType = z.infer<typeof zBar>;
1818
*/
1919
export const zFoo = z._default(z.union([
2020
z.object({
21-
foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))),
21+
foo: z.optional(z.string().check(z.regex(/^\\d{3}-\\d{2}-\\d{4}$/))),
2222
bar: z.optional(zBar),
2323
get baz(): z.ZodMiniOptional {
2424
return z.optional(z.array(z.lazy((): any => {
@@ -32,7 +32,7 @@ export const zFoo = z._default(z.union([
3232

3333
export type FooZodType = z.infer<typeof zFoo>;
3434

35-
export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz');
35+
export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\\nbar/))), 'baz');
3636

3737
export type BazZodType = z.infer<typeof zBaz>;
3838

0 commit comments

Comments
 (0)