@gabrielbryk/json-schema-to-zod 2.7.3 → 2.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -28,9 +28,6 @@ jobs:
|
|
|
28
28
|
cache: pnpm
|
|
29
29
|
registry-url: https://registry.npmjs.org
|
|
30
30
|
|
|
31
|
-
- name: Update npm (trusted publishing requires >=11.5.1)
|
|
32
|
-
run: npm install -g npm@latest
|
|
33
|
-
|
|
34
31
|
- name: Install dependencies
|
|
35
32
|
run: pnpm install --frozen-lockfile
|
|
36
33
|
|
|
@@ -46,5 +43,3 @@ jobs:
|
|
|
46
43
|
publish: pnpm changeset publish --access public
|
|
47
44
|
env:
|
|
48
45
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
49
|
-
NPM_TOKEN: ""
|
|
50
|
-
NODE_AUTH_TOKEN: ""
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @gabrielbryk/json-schema-to-zod
|
|
2
2
|
|
|
3
|
+
## 2.7.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 82aa953: Fix patternProperties validation under Zod v4 by preserving regex patterns and handling missing `ctx.path`.
|
|
8
|
+
- a501e7d: Adjust release workflow to rely on the default npm from setup-node and drop unused tokens.
|
|
9
|
+
- 43f2abc: Update object record generation to use `z.record(z.string(), …)` for Zod v4 compatibility.
|
|
10
|
+
|
|
3
11
|
## 2.7.3
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -78,16 +78,16 @@ function parseObject(objectSchema, refs) {
|
|
|
78
78
|
}
|
|
79
79
|
else {
|
|
80
80
|
if (additionalProperties) {
|
|
81
|
-
patternProperties += `z.record(z.union([${[
|
|
81
|
+
patternProperties += `z.record(z.string(), z.union([${[
|
|
82
82
|
...Object.values(parsedPatternProperties),
|
|
83
83
|
additionalProperties,
|
|
84
84
|
].join(", ")}]))`;
|
|
85
85
|
}
|
|
86
86
|
else if (Object.keys(parsedPatternProperties).length > 1) {
|
|
87
|
-
patternProperties += `z.record(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
|
|
87
|
+
patternProperties += `z.record(z.string(), z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
90
|
-
patternProperties += `z.record(${Object.values(parsedPatternProperties)})`;
|
|
90
|
+
patternProperties += `z.record(z.string(), ${Object.values(parsedPatternProperties)})`;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
patternProperties += ".superRefine((value, ctx) => {\n";
|
|
@@ -103,9 +103,8 @@ function parseObject(objectSchema, refs) {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
for (const key in objectSchema.patternProperties) {
|
|
106
|
-
const escapedPattern = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
107
106
|
patternProperties +=
|
|
108
|
-
"if (key.match(new RegExp(" + JSON.stringify(
|
|
107
|
+
"if (key.match(new RegExp(" + JSON.stringify(key) + "))) {\n";
|
|
109
108
|
if (additionalProperties) {
|
|
110
109
|
patternProperties += "evaluated = true\n";
|
|
111
110
|
}
|
|
@@ -115,7 +114,7 @@ function parseObject(objectSchema, refs) {
|
|
|
115
114
|
".safeParse(value[key])\n";
|
|
116
115
|
patternProperties += "if (!result.success) {\n";
|
|
117
116
|
patternProperties += `ctx.addIssue({
|
|
118
|
-
path: [...ctx.path, key],
|
|
117
|
+
path: [...(ctx.path ?? []), key],
|
|
119
118
|
code: 'custom',
|
|
120
119
|
message: \`Invalid input: Key matching regex /\${key}/ must match schema\`,
|
|
121
120
|
params: {
|
|
@@ -131,7 +130,7 @@ function parseObject(objectSchema, refs) {
|
|
|
131
130
|
"const result = " + additionalProperties + ".safeParse(value[key])\n";
|
|
132
131
|
patternProperties += "if (!result.success) {\n";
|
|
133
132
|
patternProperties += `ctx.addIssue({
|
|
134
|
-
path: [...ctx.path, key],
|
|
133
|
+
path: [...(ctx.path ?? []), key],
|
|
135
134
|
code: 'custom',
|
|
136
135
|
message: \`Invalid input: must match catchall schema\`,
|
|
137
136
|
params: {
|
|
@@ -170,8 +169,8 @@ function parseObject(objectSchema, refs) {
|
|
|
170
169
|
: patternProperties
|
|
171
170
|
? patternProperties
|
|
172
171
|
: additionalProperties
|
|
173
|
-
? `z.record(${additionalProperties})`
|
|
174
|
-
: `z.record(${(0, anyOrUnknown_js_1.anyOrUnknown)(refs)})`;
|
|
172
|
+
? `z.record(z.string(), ${additionalProperties})`
|
|
173
|
+
: `z.record(z.string(), ${(0, anyOrUnknown_js_1.anyOrUnknown)(refs)})`;
|
|
175
174
|
if (unevaluated === false && properties && !hasCompositionKeywords) {
|
|
176
175
|
output += ".strict()";
|
|
177
176
|
}
|
|
@@ -75,16 +75,16 @@ export function parseObject(objectSchema, refs) {
|
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
77
|
if (additionalProperties) {
|
|
78
|
-
patternProperties += `z.record(z.union([${[
|
|
78
|
+
patternProperties += `z.record(z.string(), z.union([${[
|
|
79
79
|
...Object.values(parsedPatternProperties),
|
|
80
80
|
additionalProperties,
|
|
81
81
|
].join(", ")}]))`;
|
|
82
82
|
}
|
|
83
83
|
else if (Object.keys(parsedPatternProperties).length > 1) {
|
|
84
|
-
patternProperties += `z.record(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
|
|
84
|
+
patternProperties += `z.record(z.string(), z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
|
-
patternProperties += `z.record(${Object.values(parsedPatternProperties)})`;
|
|
87
|
+
patternProperties += `z.record(z.string(), ${Object.values(parsedPatternProperties)})`;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
patternProperties += ".superRefine((value, ctx) => {\n";
|
|
@@ -100,9 +100,8 @@ export function parseObject(objectSchema, refs) {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
for (const key in objectSchema.patternProperties) {
|
|
103
|
-
const escapedPattern = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
104
103
|
patternProperties +=
|
|
105
|
-
"if (key.match(new RegExp(" + JSON.stringify(
|
|
104
|
+
"if (key.match(new RegExp(" + JSON.stringify(key) + "))) {\n";
|
|
106
105
|
if (additionalProperties) {
|
|
107
106
|
patternProperties += "evaluated = true\n";
|
|
108
107
|
}
|
|
@@ -112,7 +111,7 @@ export function parseObject(objectSchema, refs) {
|
|
|
112
111
|
".safeParse(value[key])\n";
|
|
113
112
|
patternProperties += "if (!result.success) {\n";
|
|
114
113
|
patternProperties += `ctx.addIssue({
|
|
115
|
-
path: [...ctx.path, key],
|
|
114
|
+
path: [...(ctx.path ?? []), key],
|
|
116
115
|
code: 'custom',
|
|
117
116
|
message: \`Invalid input: Key matching regex /\${key}/ must match schema\`,
|
|
118
117
|
params: {
|
|
@@ -128,7 +127,7 @@ export function parseObject(objectSchema, refs) {
|
|
|
128
127
|
"const result = " + additionalProperties + ".safeParse(value[key])\n";
|
|
129
128
|
patternProperties += "if (!result.success) {\n";
|
|
130
129
|
patternProperties += `ctx.addIssue({
|
|
131
|
-
path: [...ctx.path, key],
|
|
130
|
+
path: [...(ctx.path ?? []), key],
|
|
132
131
|
code: 'custom',
|
|
133
132
|
message: \`Invalid input: must match catchall schema\`,
|
|
134
133
|
params: {
|
|
@@ -167,8 +166,8 @@ export function parseObject(objectSchema, refs) {
|
|
|
167
166
|
: patternProperties
|
|
168
167
|
? patternProperties
|
|
169
168
|
: additionalProperties
|
|
170
|
-
? `z.record(${additionalProperties})`
|
|
171
|
-
: `z.record(${anyOrUnknown(refs)})`;
|
|
169
|
+
? `z.record(z.string(), ${additionalProperties})`
|
|
170
|
+
: `z.record(z.string(), ${anyOrUnknown(refs)})`;
|
|
172
171
|
if (unevaluated === false && properties && !hasCompositionKeywords) {
|
|
173
172
|
output += ".strict()";
|
|
174
173
|
}
|