@gabrielbryk/json-schema-to-zod 2.12.1 → 2.13.0

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.
Files changed (53) hide show
  1. package/.github/RELEASE_SETUP.md +120 -0
  2. package/.github/TOOLING_GUIDE.md +169 -0
  3. package/.github/dependabot.yml +52 -0
  4. package/.github/workflows/ci.yml +33 -0
  5. package/.github/workflows/release.yml +12 -4
  6. package/.github/workflows/security.yml +40 -0
  7. package/.husky/commit-msg +1 -0
  8. package/.husky/pre-commit +1 -0
  9. package/.lintstagedrc.json +3 -0
  10. package/.prettierrc +20 -0
  11. package/AGENTS.md +7 -0
  12. package/CHANGELOG.md +7 -4
  13. package/README.md +9 -9
  14. package/commitlint.config.js +24 -0
  15. package/createIndex.ts +4 -4
  16. package/dist/cli.js +3 -4
  17. package/dist/core/analyzeSchema.js +28 -5
  18. package/dist/core/emitZod.js +11 -4
  19. package/dist/generators/generateBundle.js +67 -92
  20. package/dist/parsers/parseAllOf.js +11 -12
  21. package/dist/parsers/parseAnyOf.js +2 -2
  22. package/dist/parsers/parseArray.js +38 -12
  23. package/dist/parsers/parseMultipleType.js +2 -2
  24. package/dist/parsers/parseNumber.js +44 -102
  25. package/dist/parsers/parseObject.js +136 -443
  26. package/dist/parsers/parseOneOf.js +57 -110
  27. package/dist/parsers/parseSchema.js +132 -55
  28. package/dist/parsers/parseSimpleDiscriminatedOneOf.js +2 -2
  29. package/dist/parsers/parseString.js +113 -253
  30. package/dist/types/Types.d.ts +22 -1
  31. package/dist/types/core/analyzeSchema.d.ts +1 -0
  32. package/dist/types/generators/generateBundle.d.ts +1 -1
  33. package/dist/utils/cliTools.js +1 -2
  34. package/dist/utils/esmEmitter.js +6 -2
  35. package/dist/utils/extractInlineObject.js +1 -3
  36. package/dist/utils/jsdocs.js +1 -4
  37. package/dist/utils/liftInlineObjects.js +76 -15
  38. package/dist/utils/resolveRef.js +35 -10
  39. package/dist/utils/schemaRepresentation.js +35 -66
  40. package/dist/zodToJsonSchema.js +1 -2
  41. package/docs/IMPROVEMENT-PLAN.md +30 -12
  42. package/docs/ZOD-V4-RECURSIVE-TYPE-LIMITATIONS.md +70 -25
  43. package/docs/proposals/allof-required-merging.md +10 -4
  44. package/docs/proposals/bundle-refactor.md +10 -4
  45. package/docs/proposals/discriminated-union-with-default.md +18 -14
  46. package/docs/proposals/inline-object-lifting.md +15 -5
  47. package/docs/proposals/ref-anchor-support.md +11 -0
  48. package/output.txt +67 -0
  49. package/package.json +18 -5
  50. package/scripts/generateWorkflowSchema.ts +5 -14
  51. package/scripts/regenerate_bundle.ts +25 -0
  52. package/tsc_output.txt +542 -0
  53. package/tsc_output_2.txt +489 -0
@@ -0,0 +1,120 @@
1
+ # Release Workflow Setup Guide
2
+
3
+ This document explains how to set up automated releases for this package.
4
+
5
+ ## Prerequisites
6
+
7
+ 1. **NPM Account**: You need an npm account with publish permissions
8
+ 2. **GitHub Repository**: Repository must be on GitHub
9
+ 3. **Repository Secrets**: Configure the following secrets in your GitHub repository
10
+
11
+ ## Setup Steps
12
+
13
+ ### 1. Create NPM Access Token
14
+
15
+ 1. Go to [npmjs.com](https://www.npmjs.com/) and log in
16
+ 2. Click on your profile → "Access Tokens"
17
+ 3. Click "Generate New Token" → "Classic Token"
18
+ 4. Select "Automation" type (for CI/CD)
19
+ 5. Copy the generated token
20
+
21
+ ### 2. Add GitHub Secret
22
+
23
+ 1. Go to your GitHub repository
24
+ 2. Navigate to Settings → Secrets and variables → Actions
25
+ 3. Click "New repository secret"
26
+ 4. Name: `NPM_TOKEN`
27
+ 5. Value: Paste your npm token
28
+ 6. Click "Add secret"
29
+
30
+ ### 3. How It Works
31
+
32
+ The release workflow (`.github/workflows/release.yml`) automatically:
33
+
34
+ 1. **On every push to `main` branch**:
35
+ - Checks for changesets
36
+ - If changesets exist, creates a "Release" PR
37
+ - The PR includes version bumps and CHANGELOG updates
38
+
39
+ 2. **When you merge the Release PR**:
40
+ - Automatically publishes to npm
41
+ - Creates GitHub releases
42
+ - Updates version tags
43
+
44
+ ### 4. Creating a Release
45
+
46
+ ```bash
47
+ # 1. Make your changes and commit them
48
+ git add .
49
+ git commit -m "feat: add new feature"
50
+
51
+ # 2. Create a changeset
52
+ pnpx changeset
53
+ # Follow the prompts:
54
+ # - Select the type of change (major/minor/patch)
55
+ # - Describe the changes for the changelog
56
+
57
+ # 3. Commit the changeset
58
+ git add .
59
+ git commit -m "chore: add changeset"
60
+
61
+ # 4. Push to main (or create a PR)
62
+ git push origin main
63
+
64
+ # 5. The workflow will create a Release PR automatically
65
+ # 6. Review and merge the Release PR to publish
66
+ ```
67
+
68
+ ## Changeset Types
69
+
70
+ - **Major** (2.0.0 → 3.0.0): Breaking changes
71
+ - **Minor** (2.0.0 → 2.1.0): New features (backward compatible)
72
+ - **Patch** (2.0.0 → 2.0.1): Bug fixes
73
+
74
+ ## Manual Release (Alternative)
75
+
76
+ If you prefer manual releases:
77
+
78
+ ```bash
79
+ # 1. Create and commit changesets as above
80
+ pnpx changeset
81
+
82
+ # 2. Version the package
83
+ pnpm run local-release
84
+
85
+ # 3. Push changes
86
+ git push --follow-tags
87
+ ```
88
+
89
+ ## Troubleshooting
90
+
91
+ ### Release workflow fails with "401 Unauthorized"
92
+
93
+ - Check that `NPM_TOKEN` secret is set correctly
94
+ - Verify the token has publish permissions
95
+ - Ensure the token hasn't expired
96
+
97
+ ### No Release PR is created
98
+
99
+ - Verify there are changesets in `.changeset/` directory
100
+ - Check the workflow logs in GitHub Actions
101
+ - Ensure you're pushing to the `main` branch
102
+
103
+ ### Package name already exists on npm
104
+
105
+ - Update the `name` field in `package.json`
106
+ - Ensure you have permissions to publish to that package name
107
+
108
+ ## Best Practices
109
+
110
+ 1. **Always create changesets** for user-facing changes
111
+ 2. **Write clear changeset descriptions** - they become your changelog
112
+ 3. **Review Release PRs carefully** before merging
113
+ 4. **Use semantic versioning** appropriately
114
+ 5. **Test locally** with `pnpm run ci` before pushing
115
+
116
+ ## Additional Resources
117
+
118
+ - [Changesets Documentation](https://github.com/changesets/changesets)
119
+ - [GitHub Actions Documentation](https://docs.github.com/en/actions)
120
+ - [npm Publishing Guide](https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry)
@@ -0,0 +1,169 @@
1
+ # Tooling Guide
2
+
3
+ This document provides an overview of all the automated tooling configured in this project.
4
+
5
+ ## 🔍 Code Quality Tools
6
+
7
+ ### ESLint
8
+
9
+ - **Purpose**: Static code analysis and linting
10
+ - **Config**: `eslint.config.js` (ESLint v9 flat config)
11
+ - **Run**: `pnpm run lint` or `pnpm run lint:fix`
12
+ - **Features**:
13
+ - TypeScript ESLint rules
14
+ - Enforced no `require` imports
15
+
16
+ ### Prettier
17
+
18
+ - **Purpose**: Code formatting
19
+ - **Config**: `.prettierrc`
20
+ - **Run**: `pnpm run format:write` or `pnpm run format:check`
21
+ - **Settings**:
22
+ - Double quotes
23
+ - Semicolons
24
+ - 100 character line width
25
+ - 2 space indentation
26
+
27
+ ### TypeScript
28
+
29
+ - **Purpose**: Type checking and compilation
30
+ - **Config**: `tsconfig.json`
31
+ - **Run**: `pnpm run build:esm`
32
+
33
+ ## ✅ Commit Quality
34
+
35
+ ### Commitlint
36
+
37
+ - **Purpose**: Enforce conventional commit messages
38
+ - **Config**: `commitlint.config.js`
39
+ - **Hook**: `.husky/commit-msg`
40
+ - **Format**: `type: subject` (e.g., `feat: add new feature`)
41
+ - **Allowed types**:
42
+ - `feat`, `fix`, `docs`, `style`, `refactor`
43
+ - `perf`, `test`, `build`, `ci`, `chore`, `revert`
44
+
45
+ ### Husky
46
+
47
+ - **Purpose**: Git hooks management
48
+ - **Config**: `.husky/` directory
49
+ - **Hooks**:
50
+ - `pre-commit`: Runs lint-staged
51
+ - `commit-msg`: Runs commitlint
52
+
53
+ ### Lint-staged
54
+
55
+ - **Purpose**: Run linters on staged files only
56
+ - **Config**: `.lintstagedrc.json`
57
+ - **Actions**:
58
+ - Format with Prettier
59
+ - Fix with ESLint
60
+
61
+ ## 🧪 Testing
62
+
63
+ ### Jest
64
+
65
+ - **Purpose**: Unit testing
66
+ - **Config**: `jest.config.mjs`
67
+ - **Run**: `pnpm run test` or `pnpm run dev` (watch mode)
68
+
69
+ ## 📦 Build & Package
70
+
71
+ - **Build**: `pnpm run build` (generates index, runs tests, and emits ESM + types)
72
+ - **Smoke test**: `pnpm run smoke:esm`
73
+
74
+ ## 📝 Version Management
75
+
76
+ ### Changesets
77
+
78
+ - **Purpose**: Version management and changelog generation
79
+ - **Config**: `.changeset/config.json`
80
+ - **Usage**:
81
+ ```bash
82
+ pnpx changeset
83
+ pnpm run local-release
84
+ ```
85
+ - **Features**:
86
+ - Semantic versioning
87
+ - Automatic CHANGELOG.md generation
88
+
89
+ ## 🤖 CI/CD
90
+
91
+ ### GitHub Actions - CI Workflow
92
+
93
+ - **File**: `.github/workflows/ci.yml`
94
+ - **Trigger**: Push and Pull Requests
95
+ - **Steps**:
96
+ 1. Install dependencies with pnpm
97
+ 2. Run full CI pipeline (`pnpm run ci`)
98
+
99
+ ### GitHub Actions - Release Workflow
100
+
101
+ - **File**: `.github/workflows/release.yml`
102
+ - **Trigger**: Push to `main` branch
103
+ - **Steps**:
104
+ 1. Build package
105
+ 2. Create Release PR (if changesets exist)
106
+ 3. Publish to npm (when Release PR is merged)
107
+ - **Setup**: See `.github/RELEASE_SETUP.md`
108
+
109
+ ### GitHub Actions - Security Audit
110
+
111
+ - **File**: `.github/workflows/security.yml`
112
+ - **Trigger**: Weekly schedule and dependency changes
113
+ - **Steps**:
114
+ 1. Run `pnpm audit`
115
+ 2. Warn on high/critical vulnerabilities
116
+
117
+ ### Dependabot
118
+
119
+ - **File**: `.github/dependabot.yml`
120
+ - **Purpose**: Automated dependency updates
121
+ - **Schedule**: Weekly on Mondays at 9:00 AM UTC
122
+ - **Features**:
123
+ - Groups minor/patch updates
124
+ - Updates GitHub Actions
125
+
126
+ ## 🔄 Workflow Summary
127
+
128
+ ### Development Workflow
129
+
130
+ ```bash
131
+ # 1. Make changes
132
+ git checkout -b feature/my-feature
133
+
134
+ # 2. Write code and tests
135
+
136
+ # 3. Commit (commitlint validates, lint-staged runs)
137
+ git commit -m "feat: add new feature"
138
+
139
+ # 4. Push and create PR
140
+ git push origin feature/my-feature
141
+
142
+ # 5. CI runs automatically on PR
143
+ # 6. Merge when CI passes
144
+ ```
145
+
146
+ ### Release Workflow
147
+
148
+ ```bash
149
+ # 1. Create a changeset
150
+ pnpx changeset
151
+
152
+ # 2. Commit changeset
153
+ git commit -m "chore: add changeset"
154
+
155
+ # 3. Push to main (or create a PR)
156
+ git push origin main
157
+
158
+ # 4. The workflow creates a Release PR automatically
159
+ # 5. Review and merge Release PR to publish
160
+ ```
161
+
162
+ ## 📊 Quality Gates
163
+
164
+ All PRs must pass:
165
+
166
+ - ✅ Build succeeds
167
+ - ✅ Code is formatted (Prettier)
168
+ - ✅ No linting errors (ESLint)
169
+ - ✅ Tests pass (Jest)
@@ -0,0 +1,52 @@
1
+ # Dependabot configuration for automated dependency updates
2
+ # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
3
+
4
+ version: 2
5
+ updates:
6
+ # Maintain npm dependencies
7
+ - package-ecosystem: "npm"
8
+ directory: "/"
9
+ schedule:
10
+ interval: "weekly"
11
+ day: "monday"
12
+ time: "09:00"
13
+ open-pull-requests-limit: 10
14
+ assignees:
15
+ - "gabrielbryk"
16
+ commit-message:
17
+ prefix: "chore"
18
+ prefix-development: "chore"
19
+ include: "scope"
20
+ labels:
21
+ - "dependencies"
22
+ - "automated"
23
+ groups:
24
+ # Group all patch and minor updates together
25
+ development-dependencies:
26
+ dependency-type: "development"
27
+ update-types:
28
+ - "minor"
29
+ - "patch"
30
+ production-dependencies:
31
+ dependency-type: "production"
32
+ update-types:
33
+ - "minor"
34
+ - "patch"
35
+
36
+ # Maintain GitHub Actions
37
+ - package-ecosystem: "github-actions"
38
+ directory: "/"
39
+ schedule:
40
+ interval: "weekly"
41
+ day: "monday"
42
+ time: "09:00"
43
+ open-pull-requests-limit: 5
44
+ assignees:
45
+ - "gabrielbryk"
46
+ commit-message:
47
+ prefix: "ci"
48
+ include: "scope"
49
+ labels:
50
+ - "dependencies"
51
+ - "github-actions"
52
+ - "automated"
@@ -0,0 +1,33 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - main
8
+
9
+ concurrency:
10
+ group: ${{ github.workflow }}-${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ ci:
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - uses: actions/checkout@v6
19
+
20
+ - name: Install pnpm
21
+ uses: pnpm/action-setup@v4
22
+
23
+ - name: Use Node.js
24
+ uses: actions/setup-node@v6
25
+ with:
26
+ node-version: "24"
27
+ cache: "pnpm"
28
+
29
+ - name: Install dependencies
30
+ run: pnpm install --frozen-lockfile
31
+
32
+ - name: Run CI
33
+ run: pnpm run ci
@@ -6,6 +6,8 @@ on:
6
6
  - main
7
7
  workflow_dispatch:
8
8
 
9
+ concurrency: ${{ github.workflow }}-${{ github.ref }}
10
+
9
11
  permissions:
10
12
  contents: write
11
13
  pull-requests: write
@@ -28,13 +30,17 @@ jobs:
28
30
  cache: pnpm
29
31
  registry-url: https://registry.npmjs.org
30
32
 
31
- - name: Install dependencies
33
+ - name: Update npm (trusted publishing requires >=11.5.1)
34
+ run: npm install -g npm@latest
35
+
36
+ - name: Install Dependencies
32
37
  run: pnpm install --frozen-lockfile
33
38
 
34
- - name: Build
35
- run: pnpm build
39
+ - name: Build Package
40
+ run: pnpm run build
36
41
 
37
- - name: Release with Changesets
42
+ - name: Create Release Pull Request or Publish to npm
43
+ id: changesets
38
44
  uses: changesets/action@v1
39
45
  with:
40
46
  commit: "ci: release"
@@ -43,3 +49,5 @@ jobs:
43
49
  publish: pnpm changeset publish --access public
44
50
  env:
45
51
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52
+ NPM_TOKEN: ""
53
+ NODE_AUTH_TOKEN: ""
@@ -0,0 +1,40 @@
1
+ name: Security Audit
2
+
3
+ on:
4
+ schedule:
5
+ # Run every Monday at 9:00 AM UTC
6
+ - cron: "0 9 * * 1"
7
+ workflow_dispatch:
8
+ pull_request:
9
+ paths:
10
+ - "package.json"
11
+ - "pnpm-lock.yaml"
12
+
13
+ jobs:
14
+ audit:
15
+ name: Security Audit
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - name: Checkout Repo
19
+ uses: actions/checkout@v6
20
+
21
+ - name: Install pnpm
22
+ uses: pnpm/action-setup@v4
23
+
24
+ - name: Setup Node.js
25
+ uses: actions/setup-node@v6
26
+ with:
27
+ node-version: "24"
28
+
29
+ - name: Run Security Audit
30
+ run: pnpm audit --audit-level=moderate
31
+ continue-on-error: true
32
+
33
+ - name: Check for Vulnerabilities
34
+ run: |
35
+ if pnpm audit --audit-level=high --json > audit.json; then
36
+ echo "No high or critical vulnerabilities found"
37
+ else
38
+ echo "::warning::High or critical vulnerabilities detected. Please review."
39
+ cat audit.json
40
+ fi
@@ -0,0 +1 @@
1
+ pnpx commitlint --edit $1
@@ -0,0 +1 @@
1
+ pnpm run lint-staged
@@ -0,0 +1,3 @@
1
+ {
2
+ "*.{js,jsx,ts,tsx,json,md,yml}": ["prettier --write", "pnpm run lint:fix"]
3
+ }
package/.prettierrc ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "arrowParens": "always",
3
+ "bracketSpacing": true,
4
+ "endOfLine": "lf",
5
+ "htmlWhitespaceSensitivity": "css",
6
+ "insertPragma": false,
7
+ "singleAttributePerLine": false,
8
+ "bracketSameLine": false,
9
+ "jsxSingleQuote": false,
10
+ "printWidth": 100,
11
+ "proseWrap": "preserve",
12
+ "quoteProps": "as-needed",
13
+ "requirePragma": false,
14
+ "semi": true,
15
+ "singleQuote": false,
16
+ "tabWidth": 2,
17
+ "trailingComma": "es5",
18
+ "useTabs": false,
19
+ "embeddedLanguageFormatting": "auto"
20
+ }
package/AGENTS.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # Repository Guidelines
2
2
 
3
3
  ## Project Structure & Module Organization
4
+
4
5
  - `src/`: TypeScript source; CLI entry in `src/cli.ts`, library entry in `src/index.ts`, conversion logic in `src/jsonSchemaToZod.ts`, parsers under `src/parsers/`, and helpers in `src/utils/`.
5
6
  - `test/`: TS test suite executed via `tsx`; fixtures live in `test/fixtures/`; snapshots in `test/generateSchemaBundle.snap.test.ts`.
6
7
  - `docs/`: Design proposals. Build outputs land in `dist/`; do not edit generated files.
7
8
  - `scripts/` and `createIndex.ts`: Codegen utilities used during builds.
8
9
 
9
10
  ## Build, Test, and Development Commands
11
+
10
12
  - Install with `pnpm install` (pinned `pnpm@10.x`).
11
13
  - `pnpm gen`: Regenerate index exports.
12
14
  - `pnpm test`: Run the TSX-based test suite.
@@ -16,29 +18,34 @@
16
18
  - `pnpm smoke:esm`: Quick check that the ESM bundle imports and runs.
17
19
 
18
20
  ## Coding Style & Naming Conventions
21
+
19
22
  - Language: TypeScript with NodeNext/ESM; keep `.js` extensions on internal imports. Package ships ESM-only with flat `dist/`; avoid adding CJS outputs or require-based entrypoints. Build config lives in `tsconfig.build.json`.
20
23
  - Indentation: 2 spaces; include semicolons; prefer camelCase for functions/vars and PascalCase for types.
21
24
  - Avoid CommonJS `require`; ESLint forbids it. Keep functions small and pure.
22
25
  - Use existing utility patterns (e.g., `withMessage`, `buildRefRegistry`) before adding helpers.
23
26
 
24
27
  ## Code Quality & Best Practices
28
+
25
29
  - Type safety first: prefer explicit generics and narrow types over `any`; keep option shapes well-typed and avoid implicit `unknown` casts.
26
30
  - Embrace SOLID: single-purpose parsers/utilities, extract shared helpers, and inject collaborators instead of hard-coding globals.
27
31
  - Validate boundary cases: cyclical refs, `$ref` resolution, discriminated unions, and recursion depth—add targeted tests when touching those paths.
28
32
  - Keep emitted code deterministic; avoid data-dependent randomness or network calls in conversion paths.
29
33
 
30
34
  ## Testing Guidelines
35
+
31
36
  - Tests use a lightweight harness in `test/suite.ts`; add new suites under `test/` mirroring module paths.
32
37
  - Prefer fixtures in `test/fixtures/` for schema examples; extend snapshots only when behavior intentionally changes.
33
38
  - Cover new parsing paths; add regression cases for edge refs/recursion.
34
39
  - Run `pnpm test` (or `pnpm dev`) before opening a PR.
35
40
 
36
41
  ## Commit & Pull Request Guidelines
42
+
37
43
  - Open an issue first; PRs without one are usually not considered (`CONTRIBUTING.md`).
38
44
  - Commit messages are short and imperative; gitmoji is welcome but optional. Keep related changes in separate commits.
39
45
  - PRs should describe the problem, approach, and risks; link the issue and note test coverage or added fixtures. Screenshots are unnecessary unless CLI UX changes.
40
46
  - Keep PR scope tight; avoid editing generated `dist/` files. Mention breaking changes explicitly.
41
47
 
42
48
  ## Security & Configuration Tips
49
+
43
50
  - Avoid adding runtime dependencies that fetch remotely; conversions should stay deterministic and offline.
44
51
  - When touching CLI paths, ensure `--module`, `--type`, and `$ref` handling stay backward compatible; add tests for recursion and bundle ordering when modifying ref logic.
package/CHANGELOG.md CHANGED
@@ -1,9 +1,16 @@
1
1
  # @gabrielbryk/json-schema-to-zod
2
2
 
3
+ ## 2.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1e42453: Trigger minor release after CI/tooling alignment.
8
+
3
9
  ## 2.12.1
4
10
 
5
11
  ### Patch Changes
6
12
 
13
+ - d57f812: Align Zod output with Zod v4 idiomatic patterns, including strict/loose object helpers, exact optional properties, and broader discriminated union detection. Also improve recursive getter emissions to avoid TS7056 via explicit type annotations.
7
14
  - e8cbafc: Fix `unevaluatedProperties: false` with `oneOf` by avoiding strict union branches, allowing base properties through, and enforcing unknown-key rejection after composition.
8
15
 
9
16
  ## 2.12.0
@@ -26,7 +33,6 @@
26
33
  ### Patch Changes
27
34
 
28
35
  - 466d672: Fix TS7056 error when generating declarations for schemas referencing recursive types
29
-
30
36
  - Add explicit type annotations to any schema that references recursive schemas (not just unions)
31
37
  - This prevents TypeScript from trying to serialize extremely large expanded types when generating .d.ts files
32
38
  - Fix type narrowing in parseObject for allOf required array handling
@@ -38,19 +44,16 @@
38
44
  - 2656c90: Fix Zod v4 type compatibility and improve discriminated union detection
39
45
 
40
46
  ### Zod v4 Type Fixes
41
-
42
47
  - Remove `ZodEffects` usage which doesn't exist in Zod v4
43
48
  - `.superRefine()` and `.refine()` no longer change the schema type
44
49
  - `.transform()` now correctly returns `ZodPipe` type instead of `ZodEffects`
45
50
 
46
51
  ### Discriminated Union Detection Improvements
47
-
48
52
  - Enhanced `findImplicitDiscriminator` to detect discriminators in `allOf` members
49
53
  - Properly resolves `$ref` when checking for discriminator values
50
54
  - Correctly collects `required` fields from both parent schema and `allOf` members
51
55
 
52
56
  ### Cleaner Output Generation
53
-
54
57
  - Simplified `parseAllOf` to avoid generating redundant `z.record().superRefine()` patterns
55
58
  - Build proper object types with specific property annotations instead of generic `ZodObject<Record<string, ZodTypeAny>>`
56
59
  - Intersection types are now properly tracked and reflected in type annotations
package/README.md CHANGED
@@ -47,15 +47,15 @@ json-refs resolve mySchema.json | json-schema-to-zod | prettier --parser typescr
47
47
 
48
48
  #### Options
49
49
 
50
- | Flag | Shorthand | Function |
51
- | -------------- | --------- | ---------------------------------------------------------------------------------------------- |
52
- | `--input` | `-i` | JSON or a source file path. Required if no data is piped. |
53
- | `--output` | `-o` | A file path to write to. If not supplied stdout will be used. |
54
- | `--name` | `-n` | The name of the schema in the output |
55
- | `--depth` | `-d` | Maximum depth of recursion in schema before falling back to `z.any()`. Defaults to 0. |
56
- | `--type` | `-t` | Export a named type along with the schema. Requires `name` to be set. |
57
- | `--noImport` | `-ni` | Removes the `import { z } from 'zod';` or equivalent from the output. |
58
- | `--withJsdocs` | `-wj` | Generate jsdocs off of the description property. |
50
+ | Flag | Shorthand | Function |
51
+ | -------------- | --------- | ------------------------------------------------------------------------------------- |
52
+ | `--input` | `-i` | JSON or a source file path. Required if no data is piped. |
53
+ | `--output` | `-o` | A file path to write to. If not supplied stdout will be used. |
54
+ | `--name` | `-n` | The name of the schema in the output |
55
+ | `--depth` | `-d` | Maximum depth of recursion in schema before falling back to `z.any()`. Defaults to 0. |
56
+ | `--type` | `-t` | Export a named type along with the schema. Requires `name` to be set. |
57
+ | `--noImport` | `-ni` | Removes the `import { z } from 'zod';` or equivalent from the output. |
58
+ | `--withJsdocs` | `-wj` | Generate jsdocs off of the description property. |
59
59
 
60
60
  ### Programmatic
61
61
 
@@ -0,0 +1,24 @@
1
+ export default {
2
+ extends: ["@commitlint/config-conventional"],
3
+ rules: {
4
+ "type-enum": [
5
+ 2,
6
+ "always",
7
+ [
8
+ "feat",
9
+ "fix",
10
+ "docs",
11
+ "style",
12
+ "refactor",
13
+ "perf",
14
+ "test",
15
+ "build",
16
+ "ci",
17
+ "chore",
18
+ "revert",
19
+ ],
20
+ ],
21
+ "subject-case": [2, "never", ["upper-case"]],
22
+ "header-max-length": [2, "always", 100],
23
+ },
24
+ };
package/createIndex.ts CHANGED
@@ -15,7 +15,7 @@ function checkSrcDir(path: string): string[] {
15
15
  if (statSync(itemPath).isDirectory()) {
16
16
  lines.push(...checkSrcDir(itemPath));
17
17
  } else if (item.endsWith(".ts")) {
18
- lines.push('export * from "./' + itemPath.slice(4, -2) + 'js"');
18
+ lines.push('export * from "./' + itemPath.slice(4, -2) + 'js";');
19
19
  }
20
20
  }
21
21
 
@@ -25,8 +25,8 @@ function checkSrcDir(path: string): string[] {
25
25
  const lines = checkSrcDir("src");
26
26
 
27
27
  lines.push(
28
- 'import { jsonSchemaToZod } from "./jsonSchemaToZod.js"',
29
- "export default jsonSchemaToZod",
28
+ 'import { jsonSchemaToZod } from "./jsonSchemaToZod.js";',
29
+ "export default jsonSchemaToZod;"
30
30
  );
31
31
 
32
- writeFileSync("./src/index.ts", lines.join("\n"));
32
+ writeFileSync("./src/index.ts", `${lines.join("\n")}\n`);
package/dist/cli.js CHANGED
@@ -7,8 +7,7 @@ const params = {
7
7
  input: {
8
8
  shorthand: "i",
9
9
  value: "string",
10
- required: process.stdin.isTTY &&
11
- "input is required when no JSON or file path is piped",
10
+ required: process.stdin.isTTY && "input is required when no JSON or file path is piped",
12
11
  description: "JSON or a source file path. Required if no data is piped.",
13
12
  },
14
13
  output: {
@@ -29,11 +28,11 @@ const params = {
29
28
  type: {
30
29
  shorthand: "t",
31
30
  value: "string",
32
- description: "The name of the (optional) inferred type export."
31
+ description: "The name of the (optional) inferred type export.",
33
32
  },
34
33
  noImport: {
35
34
  shorthand: "ni",
36
- description: "Removes the `import { z } from 'zod';` or equivalent from the output."
35
+ description: "Removes the `import { z } from 'zod';` or equivalent from the output.",
37
36
  },
38
37
  withJsdocs: {
39
38
  shorthand: "wj",