@gabrielbryk/json-schema-to-zod 2.7.2 → 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.
- package/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.github/workflows/release.yml +45 -0
- package/CHANGELOG.md +15 -0
- package/dist/cjs/parsers/parseIfThenElse.js +1 -1
- package/dist/cjs/parsers/parseObject.js +4 -4
- package/dist/cjs/parsers/parseSimpleDiscriminatedOneOf.js +5 -13
- package/dist/esm/parsers/parseIfThenElse.js +1 -1
- package/dist/esm/parsers/parseObject.js +4 -4
- package/dist/esm/parsers/parseSimpleDiscriminatedOneOf.js +5 -13
- package/package.json +2 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changesets
|
|
2
|
+
|
|
3
|
+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
4
|
+
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
|
5
|
+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
|
6
|
+
|
|
7
|
+
We have a quick list of common questions to get you started engaging with this project in
|
|
8
|
+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
|
|
3
|
+
"changelog": "@changesets/cli/changelog",
|
|
4
|
+
"commit": false,
|
|
5
|
+
"fixed": [],
|
|
6
|
+
"linked": [],
|
|
7
|
+
"access": "public",
|
|
8
|
+
"baseBranch": "main",
|
|
9
|
+
"updateInternalDependencies": "patch",
|
|
10
|
+
"ignore": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: write
|
|
11
|
+
pull-requests: write
|
|
12
|
+
id-token: write
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
release:
|
|
16
|
+
environment: npm-publish
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v5
|
|
20
|
+
|
|
21
|
+
- uses: pnpm/action-setup@v4
|
|
22
|
+
with:
|
|
23
|
+
run_install: false
|
|
24
|
+
|
|
25
|
+
- uses: actions/setup-node@v4
|
|
26
|
+
with:
|
|
27
|
+
node-version: 24
|
|
28
|
+
cache: pnpm
|
|
29
|
+
registry-url: https://registry.npmjs.org
|
|
30
|
+
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: pnpm install --frozen-lockfile
|
|
33
|
+
|
|
34
|
+
- name: Build
|
|
35
|
+
run: pnpm build
|
|
36
|
+
|
|
37
|
+
- name: Release with Changesets
|
|
38
|
+
uses: changesets/action@v1
|
|
39
|
+
with:
|
|
40
|
+
commit: "ci: release"
|
|
41
|
+
title: "ci: release"
|
|
42
|
+
version: pnpm changeset version
|
|
43
|
+
publish: pnpm changeset publish --access public
|
|
44
|
+
env:
|
|
45
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @gabrielbryk/json-schema-to-zod
|
|
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
|
+
|
|
11
|
+
## 2.7.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- d727121: Fix internal logic; publish patched release.
|
|
@@ -17,7 +17,7 @@ const parseIfThenElse = (schema, refs) => {
|
|
|
17
17
|
? ${$then}.safeParse(value)
|
|
18
18
|
: ${$else}.safeParse(value);
|
|
19
19
|
if (!result.success) {
|
|
20
|
-
result.error.
|
|
20
|
+
result.error.errors.forEach((error) => ctx.addIssue(error))
|
|
21
21
|
}
|
|
22
22
|
})`;
|
|
23
23
|
// Store original if/then/else for JSON Schema round-trip
|
|
@@ -114,7 +114,7 @@ function parseObject(objectSchema, refs) {
|
|
|
114
114
|
".safeParse(value[key])\n";
|
|
115
115
|
patternProperties += "if (!result.success) {\n";
|
|
116
116
|
patternProperties += `ctx.addIssue({
|
|
117
|
-
path: [key],
|
|
117
|
+
path: [...(ctx.path ?? []), key],
|
|
118
118
|
code: 'custom',
|
|
119
119
|
message: \`Invalid input: Key matching regex /\${key}/ must match schema\`,
|
|
120
120
|
params: {
|
|
@@ -130,7 +130,7 @@ function parseObject(objectSchema, refs) {
|
|
|
130
130
|
"const result = " + additionalProperties + ".safeParse(value[key])\n";
|
|
131
131
|
patternProperties += "if (!result.success) {\n";
|
|
132
132
|
patternProperties += `ctx.addIssue({
|
|
133
|
-
path: [key],
|
|
133
|
+
path: [...(ctx.path ?? []), key],
|
|
134
134
|
code: 'custom',
|
|
135
135
|
message: \`Invalid input: must match catchall schema\`,
|
|
136
136
|
params: {
|
|
@@ -151,10 +151,10 @@ function parseObject(objectSchema, refs) {
|
|
|
151
151
|
patternProperties += `.meta({ __jsonSchema: { patternProperties: ${patternPropsJson} } })`;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
// Check if there will be an .and() call that adds properties from oneOf/anyOf/allOf
|
|
154
|
+
// Check if there will be an .and() call that adds properties from oneOf/anyOf/allOf/if-then-else
|
|
155
155
|
// In that case, we should NOT use .strict() because it will reject the additional keys
|
|
156
156
|
// before the union gets a chance to validate them.
|
|
157
|
-
const hasCompositionKeywords = parseSchema_js_1.its.an.anyOf(objectSchema) || parseSchema_js_1.its.a.oneOf(objectSchema) || parseSchema_js_1.its.an.allOf(objectSchema);
|
|
157
|
+
const hasCompositionKeywords = parseSchema_js_1.its.an.anyOf(objectSchema) || parseSchema_js_1.its.a.oneOf(objectSchema) || parseSchema_js_1.its.an.allOf(objectSchema) || parseSchema_js_1.its.a.conditional(objectSchema);
|
|
158
158
|
let output = properties
|
|
159
159
|
? patternProperties
|
|
160
160
|
? properties + patternProperties
|
|
@@ -5,25 +5,17 @@ const parseSchema_js_1 = require("./parseSchema.js");
|
|
|
5
5
|
const anyOrUnknown_js_1 = require("../utils/anyOrUnknown.js");
|
|
6
6
|
const parseSimpleDiscriminatedOneOf = (schema, refs) => {
|
|
7
7
|
const discriminator = schema.discriminator.propertyName;
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
(discriminatorSchema.enum && discriminatorSchema.enum[0]);
|
|
13
|
-
const parsed = (0, parseSchema_js_1.parseSchema)(option, {
|
|
14
|
-
...refs,
|
|
15
|
-
path: [...refs.path, "oneOf", i],
|
|
16
|
-
});
|
|
17
|
-
const key = typeof value === "string" ? JSON.stringify(value) : JSON.stringify(String(value));
|
|
18
|
-
return `${key}: ${parsed}`;
|
|
19
|
-
});
|
|
8
|
+
const options = schema.oneOf.map((option, i) => (0, parseSchema_js_1.parseSchema)(option, {
|
|
9
|
+
...refs,
|
|
10
|
+
path: [...refs.path, "oneOf", i],
|
|
11
|
+
}));
|
|
20
12
|
return schema.oneOf.length
|
|
21
13
|
? schema.oneOf.length === 1
|
|
22
14
|
? (0, parseSchema_js_1.parseSchema)(schema.oneOf[0], {
|
|
23
15
|
...refs,
|
|
24
16
|
path: [...refs.path, "oneOf", 0],
|
|
25
17
|
})
|
|
26
|
-
: `z.discriminatedUnion("${discriminator}",
|
|
18
|
+
: `z.discriminatedUnion("${discriminator}", [${options.join(", ")}])`
|
|
27
19
|
: (0, anyOrUnknown_js_1.anyOrUnknown)(refs);
|
|
28
20
|
};
|
|
29
21
|
exports.parseSimpleDiscriminatedOneOf = parseSimpleDiscriminatedOneOf;
|
|
@@ -14,7 +14,7 @@ export const parseIfThenElse = (schema, refs) => {
|
|
|
14
14
|
? ${$then}.safeParse(value)
|
|
15
15
|
: ${$else}.safeParse(value);
|
|
16
16
|
if (!result.success) {
|
|
17
|
-
result.error.
|
|
17
|
+
result.error.errors.forEach((error) => ctx.addIssue(error))
|
|
18
18
|
}
|
|
19
19
|
})`;
|
|
20
20
|
// Store original if/then/else for JSON Schema round-trip
|
|
@@ -111,7 +111,7 @@ export function parseObject(objectSchema, refs) {
|
|
|
111
111
|
".safeParse(value[key])\n";
|
|
112
112
|
patternProperties += "if (!result.success) {\n";
|
|
113
113
|
patternProperties += `ctx.addIssue({
|
|
114
|
-
path: [key],
|
|
114
|
+
path: [...(ctx.path ?? []), key],
|
|
115
115
|
code: 'custom',
|
|
116
116
|
message: \`Invalid input: Key matching regex /\${key}/ must match schema\`,
|
|
117
117
|
params: {
|
|
@@ -127,7 +127,7 @@ export function parseObject(objectSchema, refs) {
|
|
|
127
127
|
"const result = " + additionalProperties + ".safeParse(value[key])\n";
|
|
128
128
|
patternProperties += "if (!result.success) {\n";
|
|
129
129
|
patternProperties += `ctx.addIssue({
|
|
130
|
-
path: [key],
|
|
130
|
+
path: [...(ctx.path ?? []), key],
|
|
131
131
|
code: 'custom',
|
|
132
132
|
message: \`Invalid input: must match catchall schema\`,
|
|
133
133
|
params: {
|
|
@@ -148,10 +148,10 @@ export function parseObject(objectSchema, refs) {
|
|
|
148
148
|
patternProperties += `.meta({ __jsonSchema: { patternProperties: ${patternPropsJson} } })`;
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
// Check if there will be an .and() call that adds properties from oneOf/anyOf/allOf
|
|
151
|
+
// Check if there will be an .and() call that adds properties from oneOf/anyOf/allOf/if-then-else
|
|
152
152
|
// In that case, we should NOT use .strict() because it will reject the additional keys
|
|
153
153
|
// before the union gets a chance to validate them.
|
|
154
|
-
const hasCompositionKeywords = its.an.anyOf(objectSchema) || its.a.oneOf(objectSchema) || its.an.allOf(objectSchema);
|
|
154
|
+
const hasCompositionKeywords = its.an.anyOf(objectSchema) || its.a.oneOf(objectSchema) || its.an.allOf(objectSchema) || its.a.conditional(objectSchema);
|
|
155
155
|
let output = properties
|
|
156
156
|
? patternProperties
|
|
157
157
|
? properties + patternProperties
|
|
@@ -2,24 +2,16 @@ import { parseSchema } from "./parseSchema.js";
|
|
|
2
2
|
import { anyOrUnknown } from "../utils/anyOrUnknown.js";
|
|
3
3
|
export const parseSimpleDiscriminatedOneOf = (schema, refs) => {
|
|
4
4
|
const discriminator = schema.discriminator.propertyName;
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
(discriminatorSchema.enum && discriminatorSchema.enum[0]);
|
|
10
|
-
const parsed = parseSchema(option, {
|
|
11
|
-
...refs,
|
|
12
|
-
path: [...refs.path, "oneOf", i],
|
|
13
|
-
});
|
|
14
|
-
const key = typeof value === "string" ? JSON.stringify(value) : JSON.stringify(String(value));
|
|
15
|
-
return `${key}: ${parsed}`;
|
|
16
|
-
});
|
|
5
|
+
const options = schema.oneOf.map((option, i) => parseSchema(option, {
|
|
6
|
+
...refs,
|
|
7
|
+
path: [...refs.path, "oneOf", i],
|
|
8
|
+
}));
|
|
17
9
|
return schema.oneOf.length
|
|
18
10
|
? schema.oneOf.length === 1
|
|
19
11
|
? parseSchema(schema.oneOf[0], {
|
|
20
12
|
...refs,
|
|
21
13
|
path: [...refs.path, "oneOf", 0],
|
|
22
14
|
})
|
|
23
|
-
: `z.discriminatedUnion("${discriminator}",
|
|
15
|
+
: `z.discriminatedUnion("${discriminator}", [${options.join(", ")}])`
|
|
24
16
|
: anyOrUnknown(refs);
|
|
25
17
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gabrielbryk/json-schema-to-zod",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.4",
|
|
4
4
|
"description": "Converts JSON schema objects or files into Zod schemas",
|
|
5
5
|
"types": "./dist/types/index.d.ts",
|
|
6
6
|
"bin": "./dist/cjs/cli.js",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"access": "public"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
+
"@changesets/cli": "^2.29.8",
|
|
64
65
|
"@types/json-schema": "^7.0.15",
|
|
65
66
|
"@types/node": "^20.9.0",
|
|
66
67
|
"fast-diff": "^1.3.0",
|