zod-codegen 1.0.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 (76) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +93 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.yml +70 -0
  3. package/.github/PULL_REQUEST_TEMPLATE.md +87 -0
  4. package/.github/dependabot.yml +76 -0
  5. package/.github/workflows/ci.yml +143 -0
  6. package/.github/workflows/release.yml +65 -0
  7. package/.husky/commit-msg +2 -0
  8. package/.husky/pre-commit +5 -0
  9. package/.lintstagedrc.json +4 -0
  10. package/.nvmrc +1 -0
  11. package/.prettierrc.json +7 -0
  12. package/.releaserc.json +159 -0
  13. package/CHANGELOG.md +24 -0
  14. package/CONTRIBUTING.md +274 -0
  15. package/LICENCE +201 -0
  16. package/README.md +263 -0
  17. package/SECURITY.md +108 -0
  18. package/codecov.yml +29 -0
  19. package/commitlint.config.mjs +28 -0
  20. package/dist/scripts/update-manifest.js +31 -0
  21. package/dist/src/assets/manifest.json +5 -0
  22. package/dist/src/cli.js +60 -0
  23. package/dist/src/generator.js +55 -0
  24. package/dist/src/http/fetch-client.js +141 -0
  25. package/dist/src/interfaces/code-generator.js +1 -0
  26. package/dist/src/interfaces/file-reader.js +1 -0
  27. package/dist/src/polyfills/fetch.js +18 -0
  28. package/dist/src/services/code-generator.service.js +419 -0
  29. package/dist/src/services/file-reader.service.js +25 -0
  30. package/dist/src/services/file-writer.service.js +32 -0
  31. package/dist/src/services/import-builder.service.js +45 -0
  32. package/dist/src/services/type-builder.service.js +42 -0
  33. package/dist/src/types/http.js +10 -0
  34. package/dist/src/types/openapi.js +173 -0
  35. package/dist/src/utils/error-handler.js +11 -0
  36. package/dist/src/utils/execution-time.js +3 -0
  37. package/dist/src/utils/manifest.js +9 -0
  38. package/dist/src/utils/reporter.js +15 -0
  39. package/dist/src/utils/signal-handler.js +12 -0
  40. package/dist/src/utils/tty.js +3 -0
  41. package/dist/tests/integration/cli.test.js +25 -0
  42. package/dist/tests/unit/generator.test.js +29 -0
  43. package/dist/vitest.config.js +38 -0
  44. package/eslint.config.mjs +33 -0
  45. package/package.json +102 -0
  46. package/samples/openapi.json +1 -0
  47. package/samples/saris-openapi.json +7122 -0
  48. package/samples/swagger-petstore.yaml +802 -0
  49. package/samples/swagger-saris.yaml +3585 -0
  50. package/samples/test-logical.yaml +50 -0
  51. package/scripts/update-manifest.js +31 -0
  52. package/scripts/update-manifest.ts +47 -0
  53. package/src/assets/manifest.json +5 -0
  54. package/src/cli.ts +68 -0
  55. package/src/generator.ts +61 -0
  56. package/src/http/fetch-client.ts +181 -0
  57. package/src/interfaces/code-generator.ts +25 -0
  58. package/src/interfaces/file-reader.ts +15 -0
  59. package/src/polyfills/fetch.ts +26 -0
  60. package/src/services/code-generator.service.ts +775 -0
  61. package/src/services/file-reader.service.ts +29 -0
  62. package/src/services/file-writer.service.ts +36 -0
  63. package/src/services/import-builder.service.ts +64 -0
  64. package/src/services/type-builder.service.ts +77 -0
  65. package/src/types/http.ts +35 -0
  66. package/src/types/openapi.ts +202 -0
  67. package/src/utils/error-handler.ts +13 -0
  68. package/src/utils/execution-time.ts +3 -0
  69. package/src/utils/manifest.ts +17 -0
  70. package/src/utils/reporter.ts +16 -0
  71. package/src/utils/signal-handler.ts +14 -0
  72. package/src/utils/tty.ts +3 -0
  73. package/tests/integration/cli.test.ts +29 -0
  74. package/tests/unit/generator.test.ts +36 -0
  75. package/tsconfig.json +44 -0
  76. package/vitest.config.ts +39 -0
@@ -0,0 +1,93 @@
1
+ name: Bug Report
2
+ description: File a bug report to help us improve
3
+ title: '🐛 [Bug]: '
4
+ labels: ['bug', 'triage']
5
+ body:
6
+ - type: markdown
7
+ attributes:
8
+ value: |
9
+ Thanks for taking the time to fill out this bug report! 🙏
10
+
11
+ Please search existing issues before creating a new one.
12
+
13
+ - type: textarea
14
+ id: description
15
+ attributes:
16
+ label: Bug Description
17
+ description: A clear and concise description of what the bug is.
18
+ placeholder: Tell us what happened!
19
+ validations:
20
+ required: true
21
+
22
+ - type: textarea
23
+ id: reproduction
24
+ attributes:
25
+ label: Steps to Reproduce
26
+ description: Steps to reproduce the behavior
27
+ placeholder: |
28
+ 1. Run command '...'
29
+ 2. With input file '...'
30
+ 3. See error
31
+ validations:
32
+ required: true
33
+
34
+ - type: textarea
35
+ id: expected
36
+ attributes:
37
+ label: Expected Behavior
38
+ description: A clear and concise description of what you expected to happen.
39
+ validations:
40
+ required: true
41
+
42
+ - type: textarea
43
+ id: actual
44
+ attributes:
45
+ label: Actual Behavior
46
+ description: A clear and concise description of what actually happened.
47
+ validations:
48
+ required: true
49
+
50
+ - type: textarea
51
+ id: input-file
52
+ attributes:
53
+ label: Input OpenAPI File
54
+ description: Please share the OpenAPI file that causes the issue (or a minimal reproduction)
55
+ render: yaml
56
+ validations:
57
+ required: false
58
+
59
+ - type: textarea
60
+ id: output
61
+ attributes:
62
+ label: Generated Output
63
+ description: Please share the generated code that has issues
64
+ render: typescript
65
+ validations:
66
+ required: false
67
+
68
+ - type: input
69
+ id: version
70
+ attributes:
71
+ label: zod-codegen Version
72
+ description: What version of zod-codegen are you using?
73
+ placeholder: '0.1.0'
74
+ validations:
75
+ required: true
76
+
77
+ - type: textarea
78
+ id: environment
79
+ attributes:
80
+ label: Environment
81
+ description: Please complete the following information
82
+ value: |
83
+ - OS: [e.g. iOS, Windows, Linux]
84
+ - Node.js version: [e.g. 18.0.0]
85
+ - Package manager: [e.g. npm, yarn, pnpm]
86
+ validations:
87
+ required: true
88
+
89
+ - type: textarea
90
+ id: additional
91
+ attributes:
92
+ label: Additional Context
93
+ description: Add any other context about the problem here, such as logs, screenshots, etc.
@@ -0,0 +1,70 @@
1
+ name: Feature Request
2
+ description: Suggest an idea for zod-codegen
3
+ title: '✨ [Feature]: '
4
+ labels: ['enhancement', 'triage']
5
+ body:
6
+ - type: markdown
7
+ attributes:
8
+ value: |
9
+ Thanks for suggesting a new feature! 🚀
10
+
11
+ Please search existing issues and discussions before creating a new request.
12
+
13
+ - type: textarea
14
+ id: problem
15
+ attributes:
16
+ label: Problem Statement
17
+ description: Is your feature request related to a problem? Please describe.
18
+ placeholder: I'm frustrated when...
19
+ validations:
20
+ required: true
21
+
22
+ - type: textarea
23
+ id: solution
24
+ attributes:
25
+ label: Proposed Solution
26
+ description: Describe the solution you'd like to see
27
+ placeholder: I would like to...
28
+ validations:
29
+ required: true
30
+
31
+ - type: textarea
32
+ id: alternatives
33
+ attributes:
34
+ label: Alternatives Considered
35
+ description: Describe any alternative solutions or features you've considered
36
+ validations:
37
+ required: false
38
+
39
+ - type: textarea
40
+ id: use-case
41
+ attributes:
42
+ label: Use Case
43
+ description: Describe your use case and how this feature would help
44
+ placeholder: This would help with...
45
+ validations:
46
+ required: true
47
+
48
+ - type: textarea
49
+ id: example
50
+ attributes:
51
+ label: Example
52
+ description: Provide an example of how this feature would work
53
+ render: typescript
54
+ validations:
55
+ required: false
56
+
57
+ - type: checkboxes
58
+ id: contribution
59
+ attributes:
60
+ label: Contribution
61
+ description: Would you be willing to contribute this feature?
62
+ options:
63
+ - label: I'm willing to submit a PR for this feature
64
+ required: false
65
+
66
+ - type: textarea
67
+ id: additional
68
+ attributes:
69
+ label: Additional Context
70
+ description: Add any other context, mockups, or screenshots about the feature request here.
@@ -0,0 +1,87 @@
1
+ # Pull Request
2
+
3
+ ## 📋 Description
4
+
5
+ <!-- Provide a brief description of the changes in this PR -->
6
+
7
+ ## 🔗 Related Issues
8
+
9
+ <!-- Link to any related issues -->
10
+
11
+ Fixes #(issue number)
12
+
13
+ ## 📝 Changes Made
14
+
15
+ <!-- List the main changes made in this PR -->
16
+
17
+ - [ ]
18
+ - [ ]
19
+ - [ ]
20
+
21
+ ## 🧪 Testing
22
+
23
+ <!-- Describe the tests you ran and how to reproduce them -->
24
+
25
+ - [ ] Unit tests pass
26
+ - [ ] Integration tests pass
27
+ - [ ] Manual testing completed
28
+ - [ ] New tests added (if applicable)
29
+
30
+ ### Test Commands
31
+
32
+ ```bash
33
+ npm run test
34
+ npm run test:coverage
35
+ npm run validate
36
+ ```
37
+
38
+ ## 📸 Screenshots
39
+
40
+ <!-- If applicable, add screenshots to help explain your changes -->
41
+
42
+ ## 🏁 Checklist
43
+
44
+ Please ensure your PR meets the following requirements:
45
+
46
+ ### Code Quality
47
+
48
+ - [ ] Code follows the project's coding standards
49
+ - [ ] All existing tests pass
50
+ - [ ] New tests added for new functionality
51
+ - [ ] Code is properly documented
52
+ - [ ] Type definitions are updated (if applicable)
53
+
54
+ ### Documentation
55
+
56
+ - [ ] README updated (if applicable)
57
+ - [ ] CHANGELOG updated (will be handled by semantic-release)
58
+ - [ ] JSDoc comments added for new functions
59
+
60
+ ### Git & CI
61
+
62
+ - [ ] Commit messages follow conventional commit format
63
+ - [ ] CI pipeline passes
64
+ - [ ] Branch is up to date with main
65
+ - [ ] No merge conflicts
66
+
67
+ ### Review
68
+
69
+ - [ ] Self-review completed
70
+ - [ ] Breaking changes documented
71
+ - [ ] Backward compatibility maintained (or breaking changes justified)
72
+
73
+ ## 🚀 Deployment Notes
74
+
75
+ <!-- Any special notes for deployment -->
76
+
77
+ ## 📚 Additional Notes
78
+
79
+ <!-- Any additional information that would be helpful for reviewers -->
80
+
81
+ ---
82
+
83
+ **By submitting this PR, I confirm that:**
84
+
85
+ - [ ] I have read and agree to the project's [Contributing Guidelines](CONTRIBUTING.md)
86
+ - [ ] My code follows the project's code style and conventions
87
+ - [ ] I have tested my changes thoroughly
@@ -0,0 +1,76 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'npm'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'weekly'
7
+ day: 'monday'
8
+ time: '09:00'
9
+ open-pull-requests-limit: 10
10
+ reviewers:
11
+ - 'julienandreu'
12
+ assignees:
13
+ - 'julienandreu'
14
+ commit-message:
15
+ prefix: 'chore'
16
+ prefix-development: 'chore'
17
+ include: 'scope'
18
+ labels:
19
+ - 'dependencies'
20
+ - 'automated'
21
+ versioning-strategy: increase
22
+ groups:
23
+ dev-dependencies:
24
+ patterns:
25
+ - '@types/*'
26
+ - '@eslint/*'
27
+ - '@commitlint/*'
28
+ - '@semantic-release/*'
29
+ - '@vitest/*'
30
+ - 'eslint*'
31
+ - 'prettier'
32
+ - 'typescript*'
33
+ - 'husky'
34
+ - 'lint-staged'
35
+ - 'vitest'
36
+ - 'ts-node'
37
+ update-types:
38
+ - 'minor'
39
+ - 'patch'
40
+ production-dependencies:
41
+ patterns:
42
+ - '*'
43
+ exclude-patterns:
44
+ - '@types/*'
45
+ - '@eslint/*'
46
+ - '@commitlint/*'
47
+ - '@semantic-release/*'
48
+ - '@vitest/*'
49
+ - 'eslint*'
50
+ - 'prettier'
51
+ - 'typescript*'
52
+ - 'husky'
53
+ - 'lint-staged'
54
+ - 'vitest'
55
+ - 'ts-node'
56
+ update-types:
57
+ - 'minor'
58
+ - 'patch'
59
+
60
+ - package-ecosystem: 'github-actions'
61
+ directory: '/'
62
+ schedule:
63
+ interval: 'weekly'
64
+ day: 'monday'
65
+ time: '09:00'
66
+ open-pull-requests-limit: 5
67
+ reviewers:
68
+ - 'julienandreu'
69
+ assignees:
70
+ - 'julienandreu'
71
+ commit-message:
72
+ prefix: 'ci'
73
+ include: 'scope'
74
+ labels:
75
+ - 'ci'
76
+ - 'automated'
@@ -0,0 +1,143 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main, develop]
6
+ pull_request:
7
+ branches: [main, develop]
8
+
9
+ concurrency:
10
+ group: ${{ github.workflow }}-${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ test:
15
+ name: Test
16
+ runs-on: ${{ matrix.os }}
17
+ strategy:
18
+ matrix:
19
+ node-version: [20, 22, 24]
20
+ os: [ubuntu-latest]
21
+
22
+ steps:
23
+ - name: Checkout code
24
+ uses: actions/checkout@v4
25
+ with:
26
+ fetch-depth: 0
27
+
28
+ - name: Setup Node.js ${{ matrix.node-version }}
29
+ uses: actions/setup-node@v4
30
+ with:
31
+ node-version: ${{ matrix.node-version }}
32
+ cache: 'npm'
33
+
34
+ - name: Install dependencies
35
+ run: npm ci
36
+
37
+ - name: Run type check
38
+ run: npm run type-check
39
+
40
+ - name: Run linter
41
+ run: npm run lint:check
42
+
43
+ - name: Run formatter check
44
+ run: npm run format:check
45
+
46
+ - name: Build project
47
+ run: npm run build
48
+
49
+ - name: Run tests
50
+ run: npm run test:coverage
51
+
52
+ - name: Upload coverage to Codecov
53
+ if: matrix.node-version == 20 && matrix.os == 'ubuntu-latest'
54
+ uses: codecov/codecov-action@v4
55
+ with:
56
+ token: ${{ secrets.CODECOV_TOKEN }}
57
+ file: ./coverage/lcov.info
58
+ flags: unittests
59
+ name: codecov-umbrella
60
+
61
+ security:
62
+ name: Security Audit
63
+ runs-on: ubuntu-latest
64
+
65
+ steps:
66
+ - name: Checkout code
67
+ uses: actions/checkout@v4
68
+
69
+ - name: Setup Node.js
70
+ uses: actions/setup-node@v4
71
+ with:
72
+ node-version: 20
73
+ cache: 'npm'
74
+
75
+ - name: Install dependencies
76
+ run: npm ci
77
+
78
+ - name: Run security audit
79
+ run: npm audit --audit-level high
80
+
81
+ build:
82
+ name: Build & Package
83
+ runs-on: ubuntu-latest
84
+ needs: [test, security]
85
+
86
+ steps:
87
+ - name: Checkout code
88
+ uses: actions/checkout@v4
89
+
90
+ - name: Setup Node.js
91
+ uses: actions/setup-node@v4
92
+ with:
93
+ node-version: 22
94
+ cache: 'npm'
95
+
96
+ - name: Install dependencies
97
+ run: npm ci
98
+
99
+ - name: Build project
100
+ run: npm run build
101
+
102
+ - name: Test CLI
103
+ run: |
104
+ echo '{"openapi": "3.0.0", "info": {"title": "Test", "version": "1.0.0"}, "paths": {}}' > test-openapi.json
105
+ node ./dist/src/cli.js --input ./test-openapi.json --output generated
106
+ ls -la generated/
107
+ test -e "generated/type.ts"
108
+
109
+ - name: Upload build artifacts
110
+ uses: actions/upload-artifact@v4
111
+ with:
112
+ name: build-${{ github.sha }}
113
+ path: dist/
114
+ retention-days: 30
115
+
116
+ release-preview:
117
+ name: Release Preview
118
+ runs-on: ubuntu-latest
119
+ if: github.event_name == 'pull_request' && github.base_ref == 'main'
120
+ needs: [test, security]
121
+
122
+ steps:
123
+ - name: Checkout code
124
+ uses: actions/checkout@v4
125
+ with:
126
+ fetch-depth: 0
127
+
128
+ - name: Setup Node.js
129
+ uses: actions/setup-node@v4
130
+ with:
131
+ node-version: 22
132
+ cache: 'npm'
133
+
134
+ - name: Install dependencies
135
+ run: npm ci
136
+
137
+ - name: Build project
138
+ run: npm run build
139
+
140
+ - name: Preview semantic-release
141
+ env:
142
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
143
+ run: npm run release:dry
@@ -0,0 +1,65 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ permissions:
9
+ contents: write
10
+ issues: write
11
+ pull-requests: write
12
+ id-token: write
13
+
14
+ jobs:
15
+ release:
16
+ name: Release
17
+ runs-on: ubuntu-latest
18
+ if: github.repository == 'julienandreu/zod-codegen'
19
+ environment: production
20
+
21
+ steps:
22
+ - name: Checkout code
23
+ uses: actions/checkout@v4
24
+ with:
25
+ fetch-depth: 0
26
+ token: ${{ secrets.GITHUB_TOKEN }}
27
+
28
+ - name: Setup Node.js
29
+ uses: actions/setup-node@v4
30
+ with:
31
+ node-version: 22
32
+ cache: 'npm'
33
+ registry-url: 'https://registry.npmjs.org'
34
+
35
+ - name: Install dependencies
36
+ run: npm ci
37
+
38
+ - name: Run type check
39
+ run: npm run type-check
40
+
41
+ - name: Run linter check
42
+ run: npm run lint:check
43
+
44
+ - name: Run formatter check
45
+ run: npm run format:check
46
+
47
+ - name: Run tests with coverage
48
+ run: npm run test:coverage
49
+
50
+ - name: Build project
51
+ run: npm run build
52
+
53
+ - name: Test CLI functionality
54
+ run: |
55
+ echo '{"openapi": "3.0.0", "info": {"title": "Test", "version": "1.0.0"}, "paths": {}}' > test-openapi.json
56
+ node ./dist/src/cli.js --input ./test-openapi.json --output generated
57
+ test -e "generated/type.ts"
58
+ rm -rf generated test-openapi.json
59
+
60
+ - name: Release and Publish
61
+ env:
62
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
64
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
65
+ run: npx semantic-release
@@ -0,0 +1,2 @@
1
+ # Run commitlint to check commit message format
2
+ npx --no -- commitlint --edit $1
@@ -0,0 +1,5 @@
1
+ # Run lint-staged for staged files
2
+ npx lint-staged
3
+
4
+ # Run type checking
5
+ npm run type-check
@@ -0,0 +1,4 @@
1
+ {
2
+ "*.{ts,tsx,js,jsx}": ["eslint --fix", "prettier --write"],
3
+ "*.{json,md,yml,yaml}": ["prettier --write"]
4
+ }
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 20.18.0
@@ -0,0 +1,7 @@
1
+ {
2
+ "bracketSameLine": true,
3
+ "bracketSpacing": false,
4
+ "printWidth": 120,
5
+ "singleQuote": true,
6
+ "trailingComma": "all"
7
+ }