django-ninja-ts 1.0.0__tar.gz
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.
- django_ninja_ts-1.0.0/LICENSE +21 -0
- django_ninja_ts-1.0.0/PKG-INFO +300 -0
- django_ninja_ts-1.0.0/README.md +258 -0
- django_ninja_ts-1.0.0/django_ninja_ts/__init__.py +5 -0
- django_ninja_ts-1.0.0/django_ninja_ts/apps.py +166 -0
- django_ninja_ts-1.0.0/django_ninja_ts/management/__init__.py +1 -0
- django_ninja_ts-1.0.0/django_ninja_ts/management/commands/__init__.py +1 -0
- django_ninja_ts-1.0.0/django_ninja_ts/management/commands/runserver.py +326 -0
- django_ninja_ts-1.0.0/django_ninja_ts/py.typed +0 -0
- django_ninja_ts-1.0.0/django_ninja_ts.egg-info/PKG-INFO +300 -0
- django_ninja_ts-1.0.0/django_ninja_ts.egg-info/SOURCES.txt +15 -0
- django_ninja_ts-1.0.0/django_ninja_ts.egg-info/dependency_links.txt +1 -0
- django_ninja_ts-1.0.0/django_ninja_ts.egg-info/requires.txt +9 -0
- django_ninja_ts-1.0.0/django_ninja_ts.egg-info/top_level.txt +1 -0
- django_ninja_ts-1.0.0/pyproject.toml +133 -0
- django_ninja_ts-1.0.0/setup.cfg +4 -0
- django_ninja_ts-1.0.0/tests/test_runserver.py +784 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Django Ninja TS Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-ninja-ts
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Auto-generate TypeScript clients for Django Ninja during runserver
|
|
5
|
+
Author: Django Ninja TS Contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/fa-krug/django-ninja-ts
|
|
8
|
+
Project-URL: Repository, https://github.com/fa-krug/django-ninja-ts
|
|
9
|
+
Project-URL: Issues, https://github.com/fa-krug/django-ninja-ts/issues
|
|
10
|
+
Keywords: django,ninja,typescript,openapi,codegen
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Web Environment
|
|
13
|
+
Classifier: Framework :: Django
|
|
14
|
+
Classifier: Framework :: Django :: 4.0
|
|
15
|
+
Classifier: Framework :: Django :: 4.1
|
|
16
|
+
Classifier: Framework :: Django :: 4.2
|
|
17
|
+
Classifier: Framework :: Django :: 5.0
|
|
18
|
+
Classifier: Intended Audience :: Developers
|
|
19
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
27
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
28
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
29
|
+
Classifier: Typing :: Typed
|
|
30
|
+
Requires-Python: >=3.8
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Requires-Dist: Django>=4.0
|
|
34
|
+
Requires-Dist: django-ninja>=1.0
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-django>=4.5; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest-mock>=3.10; extra == "dev"
|
|
39
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
40
|
+
Requires-Dist: pre-commit>=3.0; extra == "dev"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# Django Ninja TS Generator
|
|
44
|
+
|
|
45
|
+
Automatically builds your TypeScript client whenever your Django Ninja schema changes.
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
1. Install the package:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install django-ninja-ts
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
2. Add to `INSTALLED_APPS` in `settings.py`:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
INSTALLED_APPS = [
|
|
59
|
+
# ...
|
|
60
|
+
'django.contrib.staticfiles',
|
|
61
|
+
'django_ninja_ts', # Add this
|
|
62
|
+
# ...
|
|
63
|
+
]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Requirements
|
|
67
|
+
|
|
68
|
+
This package requires the following external dependencies:
|
|
69
|
+
|
|
70
|
+
- **Node.js** (for `npx`)
|
|
71
|
+
- **Java JRE** (for OpenAPI Generator)
|
|
72
|
+
|
|
73
|
+
The package will provide installation instructions if these are missing.
|
|
74
|
+
|
|
75
|
+
## Configuration
|
|
76
|
+
|
|
77
|
+
Add these settings to your `settings.py`:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import os
|
|
81
|
+
|
|
82
|
+
# Path to your NinjaAPI instance (dot notation)
|
|
83
|
+
NINJA_TS_API = 'myproject.api.api'
|
|
84
|
+
|
|
85
|
+
# Where to output the generated client
|
|
86
|
+
NINJA_TS_OUTPUT_DIR = os.path.join(BASE_DIR, '../frontend/src/app/shared/api')
|
|
87
|
+
|
|
88
|
+
# Optional: Debounce time in seconds (prevents rapid rebuilds on "Save All")
|
|
89
|
+
# Default: 1.0
|
|
90
|
+
NINJA_TS_DEBOUNCE_SECONDS = 0.5
|
|
91
|
+
|
|
92
|
+
# Optional: Override generator arguments
|
|
93
|
+
# Default: ['generate', '-g', 'typescript-fetch', '-p', 'removeOperationIdPrefix=true']
|
|
94
|
+
# NINJA_TS_CMD_ARGS = ['generate', '-g', 'typescript-axios']
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## How It Works
|
|
98
|
+
|
|
99
|
+
1. When you run `python manage.py runserver`, the package intercepts the command
|
|
100
|
+
2. It loads your Django Ninja API and extracts the OpenAPI schema
|
|
101
|
+
3. It calculates a hash of the schema and compares it to the previous build
|
|
102
|
+
4. If the schema has changed, it runs `openapi-generator-cli` via `npx` to generate the TypeScript client
|
|
103
|
+
5. The hash is stored in `.schema.hash` in the output directory to avoid unnecessary rebuilds
|
|
104
|
+
|
|
105
|
+
## Configuration Options
|
|
106
|
+
|
|
107
|
+
| Setting | Required | Default | Description |
|
|
108
|
+
|---------|----------|---------|-------------|
|
|
109
|
+
| `NINJA_TS_API` | Yes | - | Dot-notation path to your NinjaAPI instance |
|
|
110
|
+
| `NINJA_TS_OUTPUT_DIR` | Yes | - | Directory where the TypeScript client will be generated |
|
|
111
|
+
| `NINJA_TS_DEBOUNCE_SECONDS` | No | `1.0` | Delay before generation to handle rapid file saves |
|
|
112
|
+
| `NINJA_TS_CMD_ARGS` | No | See below | Arguments passed to openapi-generator-cli |
|
|
113
|
+
|
|
114
|
+
### Default Generator Arguments
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
['generate', '-g', 'typescript-fetch', '-p', 'removeOperationIdPrefix=true']
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Example: Using Axios
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
NINJA_TS_CMD_ARGS = ['generate', '-g', 'typescript-axios']
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Example: Using Angular
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
NINJA_TS_CMD_ARGS = ['generate', '-g', 'typescript-angular', '-p', 'removeOperationIdPrefix=true']
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Logging
|
|
133
|
+
|
|
134
|
+
The package uses Python's standard logging module. To see debug output, configure logging in your settings:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
LOGGING = {
|
|
138
|
+
'version': 1,
|
|
139
|
+
'disable_existing_loggers': False,
|
|
140
|
+
'handlers': {
|
|
141
|
+
'console': {
|
|
142
|
+
'class': 'logging.StreamHandler',
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
'loggers': {
|
|
146
|
+
'django_ninja_ts': {
|
|
147
|
+
'handlers': ['console'],
|
|
148
|
+
'level': 'DEBUG',
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Troubleshooting
|
|
155
|
+
|
|
156
|
+
### Common Issues
|
|
157
|
+
|
|
158
|
+
#### "Module not found" error
|
|
159
|
+
|
|
160
|
+
**Problem:** You see an error like `Generation Error: Module not found: No module named 'myapp'`
|
|
161
|
+
|
|
162
|
+
**Solution:** Ensure `NINJA_TS_API` contains a valid import path to your NinjaAPI instance:
|
|
163
|
+
```python
|
|
164
|
+
# Correct - full import path
|
|
165
|
+
NINJA_TS_API = 'myapp.api.api'
|
|
166
|
+
|
|
167
|
+
# Incorrect - missing module path
|
|
168
|
+
NINJA_TS_API = 'api'
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### "does not have 'get_openapi_schema' method" error
|
|
172
|
+
|
|
173
|
+
**Problem:** The object at your `NINJA_TS_API` path is not a NinjaAPI instance.
|
|
174
|
+
|
|
175
|
+
**Solution:** Ensure you're pointing to the actual NinjaAPI instance, not a module or router:
|
|
176
|
+
```python
|
|
177
|
+
# In myapp/api.py
|
|
178
|
+
from ninja import NinjaAPI
|
|
179
|
+
api = NinjaAPI() # This is what NINJA_TS_API should point to
|
|
180
|
+
|
|
181
|
+
# In settings.py
|
|
182
|
+
NINJA_TS_API = 'myapp.api.api' # Points to the 'api' variable in myapp/api.py
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### "Invalid OpenAPI schema" error
|
|
186
|
+
|
|
187
|
+
**Problem:** The schema returned by your API is missing required OpenAPI fields.
|
|
188
|
+
|
|
189
|
+
**Solution:** This usually indicates a configuration issue with your NinjaAPI. Ensure your API has:
|
|
190
|
+
- A title (set in NinjaAPI constructor or via `title` parameter)
|
|
191
|
+
- At least one endpoint registered
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
api = NinjaAPI(title="My API", version="1.0.0")
|
|
195
|
+
|
|
196
|
+
@api.get("/health")
|
|
197
|
+
def health(request):
|
|
198
|
+
return {"status": "ok"}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
#### Generation hangs indefinitely
|
|
202
|
+
|
|
203
|
+
**Problem:** The TypeScript generation process never completes.
|
|
204
|
+
|
|
205
|
+
**Solution:** The package has a 120-second timeout by default. If generation regularly times out:
|
|
206
|
+
1. Check that Java and Node.js are properly installed
|
|
207
|
+
2. Try running `npx openapi-generator-cli generate --help` manually
|
|
208
|
+
3. Check for network issues (first run downloads the generator)
|
|
209
|
+
|
|
210
|
+
#### "Output directory parent is not writable" error
|
|
211
|
+
|
|
212
|
+
**Problem:** The package cannot create files in the specified output directory.
|
|
213
|
+
|
|
214
|
+
**Solution:** Ensure the parent directory of `NINJA_TS_OUTPUT_DIR` exists and has write permissions:
|
|
215
|
+
```bash
|
|
216
|
+
# Check permissions
|
|
217
|
+
ls -la /path/to/parent/directory
|
|
218
|
+
|
|
219
|
+
# Fix permissions if needed
|
|
220
|
+
chmod 755 /path/to/parent/directory
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### Schema not regenerating after changes
|
|
224
|
+
|
|
225
|
+
**Problem:** You've made API changes but the TypeScript client isn't updating.
|
|
226
|
+
|
|
227
|
+
**Solution:**
|
|
228
|
+
1. Delete the `.schema.hash` file in your output directory
|
|
229
|
+
2. Restart the development server
|
|
230
|
+
3. If using `NINJA_TS_DEBOUNCE_SECONDS`, wait for the debounce period
|
|
231
|
+
|
|
232
|
+
#### Windows-specific issues
|
|
233
|
+
|
|
234
|
+
**Problem:** Commands fail on Windows with shell-related errors.
|
|
235
|
+
|
|
236
|
+
**Solution:** The package automatically uses `shell=True` on Windows for `npx` compatibility. If you still have issues:
|
|
237
|
+
1. Ensure Node.js is in your PATH
|
|
238
|
+
2. Try running from PowerShell instead of Command Prompt
|
|
239
|
+
3. Run `npx openapi-generator-cli` manually to verify setup
|
|
240
|
+
|
|
241
|
+
### Configuration Validation
|
|
242
|
+
|
|
243
|
+
The package validates your configuration at startup using Django's system checks. Run checks manually with:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
python manage.py check
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
This will report any configuration errors like:
|
|
250
|
+
- Missing required settings
|
|
251
|
+
- Invalid setting types
|
|
252
|
+
- Unwritable output directories
|
|
253
|
+
|
|
254
|
+
### Debug Mode
|
|
255
|
+
|
|
256
|
+
Enable debug logging to see detailed information about the generation process:
|
|
257
|
+
|
|
258
|
+
```python
|
|
259
|
+
LOGGING = {
|
|
260
|
+
'version': 1,
|
|
261
|
+
'loggers': {
|
|
262
|
+
'django_ninja_ts': {
|
|
263
|
+
'handlers': ['console'],
|
|
264
|
+
'level': 'DEBUG',
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Supported OpenAPI Generator Versions
|
|
271
|
+
|
|
272
|
+
This package works with any version of `@openapitools/openapi-generator-cli` available via npm. The generator is automatically downloaded on first use.
|
|
273
|
+
|
|
274
|
+
## Contributing
|
|
275
|
+
|
|
276
|
+
### Commit Messages
|
|
277
|
+
|
|
278
|
+
This project uses [Conventional Commits](https://www.conventionalcommits.org/) for commit messages.
|
|
279
|
+
|
|
280
|
+
**Format:** `<type>(<scope>): <description>`
|
|
281
|
+
|
|
282
|
+
**Types:**
|
|
283
|
+
- `feat` - New features
|
|
284
|
+
- `fix` - Bug fixes
|
|
285
|
+
- `docs` - Documentation changes
|
|
286
|
+
- `style` - Code style changes (formatting, whitespace)
|
|
287
|
+
- `refactor` - Code refactoring without feature changes
|
|
288
|
+
- `test` - Adding or updating tests
|
|
289
|
+
- `chore` - Maintenance tasks, dependencies, configs
|
|
290
|
+
|
|
291
|
+
**Examples:**
|
|
292
|
+
```bash
|
|
293
|
+
feat(generator): add support for axios client
|
|
294
|
+
fix(runserver): handle missing Java dependency gracefully
|
|
295
|
+
docs(readme): add troubleshooting section
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## License
|
|
299
|
+
|
|
300
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# Django Ninja TS Generator
|
|
2
|
+
|
|
3
|
+
Automatically builds your TypeScript client whenever your Django Ninja schema changes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
1. Install the package:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install django-ninja-ts
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
2. Add to `INSTALLED_APPS` in `settings.py`:
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
INSTALLED_APPS = [
|
|
17
|
+
# ...
|
|
18
|
+
'django.contrib.staticfiles',
|
|
19
|
+
'django_ninja_ts', # Add this
|
|
20
|
+
# ...
|
|
21
|
+
]
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Requirements
|
|
25
|
+
|
|
26
|
+
This package requires the following external dependencies:
|
|
27
|
+
|
|
28
|
+
- **Node.js** (for `npx`)
|
|
29
|
+
- **Java JRE** (for OpenAPI Generator)
|
|
30
|
+
|
|
31
|
+
The package will provide installation instructions if these are missing.
|
|
32
|
+
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
35
|
+
Add these settings to your `settings.py`:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import os
|
|
39
|
+
|
|
40
|
+
# Path to your NinjaAPI instance (dot notation)
|
|
41
|
+
NINJA_TS_API = 'myproject.api.api'
|
|
42
|
+
|
|
43
|
+
# Where to output the generated client
|
|
44
|
+
NINJA_TS_OUTPUT_DIR = os.path.join(BASE_DIR, '../frontend/src/app/shared/api')
|
|
45
|
+
|
|
46
|
+
# Optional: Debounce time in seconds (prevents rapid rebuilds on "Save All")
|
|
47
|
+
# Default: 1.0
|
|
48
|
+
NINJA_TS_DEBOUNCE_SECONDS = 0.5
|
|
49
|
+
|
|
50
|
+
# Optional: Override generator arguments
|
|
51
|
+
# Default: ['generate', '-g', 'typescript-fetch', '-p', 'removeOperationIdPrefix=true']
|
|
52
|
+
# NINJA_TS_CMD_ARGS = ['generate', '-g', 'typescript-axios']
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## How It Works
|
|
56
|
+
|
|
57
|
+
1. When you run `python manage.py runserver`, the package intercepts the command
|
|
58
|
+
2. It loads your Django Ninja API and extracts the OpenAPI schema
|
|
59
|
+
3. It calculates a hash of the schema and compares it to the previous build
|
|
60
|
+
4. If the schema has changed, it runs `openapi-generator-cli` via `npx` to generate the TypeScript client
|
|
61
|
+
5. The hash is stored in `.schema.hash` in the output directory to avoid unnecessary rebuilds
|
|
62
|
+
|
|
63
|
+
## Configuration Options
|
|
64
|
+
|
|
65
|
+
| Setting | Required | Default | Description |
|
|
66
|
+
|---------|----------|---------|-------------|
|
|
67
|
+
| `NINJA_TS_API` | Yes | - | Dot-notation path to your NinjaAPI instance |
|
|
68
|
+
| `NINJA_TS_OUTPUT_DIR` | Yes | - | Directory where the TypeScript client will be generated |
|
|
69
|
+
| `NINJA_TS_DEBOUNCE_SECONDS` | No | `1.0` | Delay before generation to handle rapid file saves |
|
|
70
|
+
| `NINJA_TS_CMD_ARGS` | No | See below | Arguments passed to openapi-generator-cli |
|
|
71
|
+
|
|
72
|
+
### Default Generator Arguments
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
['generate', '-g', 'typescript-fetch', '-p', 'removeOperationIdPrefix=true']
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Example: Using Axios
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
NINJA_TS_CMD_ARGS = ['generate', '-g', 'typescript-axios']
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Example: Using Angular
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
NINJA_TS_CMD_ARGS = ['generate', '-g', 'typescript-angular', '-p', 'removeOperationIdPrefix=true']
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Logging
|
|
91
|
+
|
|
92
|
+
The package uses Python's standard logging module. To see debug output, configure logging in your settings:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
LOGGING = {
|
|
96
|
+
'version': 1,
|
|
97
|
+
'disable_existing_loggers': False,
|
|
98
|
+
'handlers': {
|
|
99
|
+
'console': {
|
|
100
|
+
'class': 'logging.StreamHandler',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
'loggers': {
|
|
104
|
+
'django_ninja_ts': {
|
|
105
|
+
'handlers': ['console'],
|
|
106
|
+
'level': 'DEBUG',
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Troubleshooting
|
|
113
|
+
|
|
114
|
+
### Common Issues
|
|
115
|
+
|
|
116
|
+
#### "Module not found" error
|
|
117
|
+
|
|
118
|
+
**Problem:** You see an error like `Generation Error: Module not found: No module named 'myapp'`
|
|
119
|
+
|
|
120
|
+
**Solution:** Ensure `NINJA_TS_API` contains a valid import path to your NinjaAPI instance:
|
|
121
|
+
```python
|
|
122
|
+
# Correct - full import path
|
|
123
|
+
NINJA_TS_API = 'myapp.api.api'
|
|
124
|
+
|
|
125
|
+
# Incorrect - missing module path
|
|
126
|
+
NINJA_TS_API = 'api'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
#### "does not have 'get_openapi_schema' method" error
|
|
130
|
+
|
|
131
|
+
**Problem:** The object at your `NINJA_TS_API` path is not a NinjaAPI instance.
|
|
132
|
+
|
|
133
|
+
**Solution:** Ensure you're pointing to the actual NinjaAPI instance, not a module or router:
|
|
134
|
+
```python
|
|
135
|
+
# In myapp/api.py
|
|
136
|
+
from ninja import NinjaAPI
|
|
137
|
+
api = NinjaAPI() # This is what NINJA_TS_API should point to
|
|
138
|
+
|
|
139
|
+
# In settings.py
|
|
140
|
+
NINJA_TS_API = 'myapp.api.api' # Points to the 'api' variable in myapp/api.py
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### "Invalid OpenAPI schema" error
|
|
144
|
+
|
|
145
|
+
**Problem:** The schema returned by your API is missing required OpenAPI fields.
|
|
146
|
+
|
|
147
|
+
**Solution:** This usually indicates a configuration issue with your NinjaAPI. Ensure your API has:
|
|
148
|
+
- A title (set in NinjaAPI constructor or via `title` parameter)
|
|
149
|
+
- At least one endpoint registered
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
api = NinjaAPI(title="My API", version="1.0.0")
|
|
153
|
+
|
|
154
|
+
@api.get("/health")
|
|
155
|
+
def health(request):
|
|
156
|
+
return {"status": "ok"}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### Generation hangs indefinitely
|
|
160
|
+
|
|
161
|
+
**Problem:** The TypeScript generation process never completes.
|
|
162
|
+
|
|
163
|
+
**Solution:** The package has a 120-second timeout by default. If generation regularly times out:
|
|
164
|
+
1. Check that Java and Node.js are properly installed
|
|
165
|
+
2. Try running `npx openapi-generator-cli generate --help` manually
|
|
166
|
+
3. Check for network issues (first run downloads the generator)
|
|
167
|
+
|
|
168
|
+
#### "Output directory parent is not writable" error
|
|
169
|
+
|
|
170
|
+
**Problem:** The package cannot create files in the specified output directory.
|
|
171
|
+
|
|
172
|
+
**Solution:** Ensure the parent directory of `NINJA_TS_OUTPUT_DIR` exists and has write permissions:
|
|
173
|
+
```bash
|
|
174
|
+
# Check permissions
|
|
175
|
+
ls -la /path/to/parent/directory
|
|
176
|
+
|
|
177
|
+
# Fix permissions if needed
|
|
178
|
+
chmod 755 /path/to/parent/directory
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Schema not regenerating after changes
|
|
182
|
+
|
|
183
|
+
**Problem:** You've made API changes but the TypeScript client isn't updating.
|
|
184
|
+
|
|
185
|
+
**Solution:**
|
|
186
|
+
1. Delete the `.schema.hash` file in your output directory
|
|
187
|
+
2. Restart the development server
|
|
188
|
+
3. If using `NINJA_TS_DEBOUNCE_SECONDS`, wait for the debounce period
|
|
189
|
+
|
|
190
|
+
#### Windows-specific issues
|
|
191
|
+
|
|
192
|
+
**Problem:** Commands fail on Windows with shell-related errors.
|
|
193
|
+
|
|
194
|
+
**Solution:** The package automatically uses `shell=True` on Windows for `npx` compatibility. If you still have issues:
|
|
195
|
+
1. Ensure Node.js is in your PATH
|
|
196
|
+
2. Try running from PowerShell instead of Command Prompt
|
|
197
|
+
3. Run `npx openapi-generator-cli` manually to verify setup
|
|
198
|
+
|
|
199
|
+
### Configuration Validation
|
|
200
|
+
|
|
201
|
+
The package validates your configuration at startup using Django's system checks. Run checks manually with:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
python manage.py check
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
This will report any configuration errors like:
|
|
208
|
+
- Missing required settings
|
|
209
|
+
- Invalid setting types
|
|
210
|
+
- Unwritable output directories
|
|
211
|
+
|
|
212
|
+
### Debug Mode
|
|
213
|
+
|
|
214
|
+
Enable debug logging to see detailed information about the generation process:
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
LOGGING = {
|
|
218
|
+
'version': 1,
|
|
219
|
+
'loggers': {
|
|
220
|
+
'django_ninja_ts': {
|
|
221
|
+
'handlers': ['console'],
|
|
222
|
+
'level': 'DEBUG',
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Supported OpenAPI Generator Versions
|
|
229
|
+
|
|
230
|
+
This package works with any version of `@openapitools/openapi-generator-cli` available via npm. The generator is automatically downloaded on first use.
|
|
231
|
+
|
|
232
|
+
## Contributing
|
|
233
|
+
|
|
234
|
+
### Commit Messages
|
|
235
|
+
|
|
236
|
+
This project uses [Conventional Commits](https://www.conventionalcommits.org/) for commit messages.
|
|
237
|
+
|
|
238
|
+
**Format:** `<type>(<scope>): <description>`
|
|
239
|
+
|
|
240
|
+
**Types:**
|
|
241
|
+
- `feat` - New features
|
|
242
|
+
- `fix` - Bug fixes
|
|
243
|
+
- `docs` - Documentation changes
|
|
244
|
+
- `style` - Code style changes (formatting, whitespace)
|
|
245
|
+
- `refactor` - Code refactoring without feature changes
|
|
246
|
+
- `test` - Adding or updating tests
|
|
247
|
+
- `chore` - Maintenance tasks, dependencies, configs
|
|
248
|
+
|
|
249
|
+
**Examples:**
|
|
250
|
+
```bash
|
|
251
|
+
feat(generator): add support for axios client
|
|
252
|
+
fix(runserver): handle missing Java dependency gracefully
|
|
253
|
+
docs(readme): add troubleshooting section
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## License
|
|
257
|
+
|
|
258
|
+
MIT License - see [LICENSE](LICENSE) for details.
|