|
4 | 4 | [](https://github.com/phillipdupuis/pydantic-to-typescript/actions/workflows/cicd.yml)
|
5 | 5 | [](https://coveralls.io/github/phillipdupuis/pydantic-to-typescript?branch=master)
|
6 | 6 |
|
7 |
| -A simple CLI tool for converting pydantic models into typescript interfaces. Useful for any scenario in which python and javascript applications are interacting, since it allows you to have a single source of truth for type definitions. |
| 7 | +A simple CLI tool for converting pydantic models into typescript interfaces. |
| 8 | +It supports all versions of pydantic, with polyfills for older versions to ensure that the resulting typescript definitions are stable and accurate. |
8 | 9 |
|
9 |
| -This tool requires that you have the lovely json2ts CLI utility installed. Instructions can be found here: https://www.npmjs.com/package/json-schema-to-typescript |
| 10 | +Useful for any scenario in which python and javascript applications are interacting, since it allows you to have a single source of truth for type definitions. |
| 11 | + |
| 12 | +This tool requires that you have the lovely json2ts CLI utility installed. |
| 13 | +Instructions can be found here: https://www.npmjs.com/package/json-schema-to-typescript |
10 | 14 |
|
11 | 15 | ### Installation
|
12 | 16 |
|
13 | 17 | ```bash
|
14 | 18 | $ pip install pydantic-to-typescript
|
15 | 19 | ```
|
16 | 20 |
|
17 |
| ---- |
| 21 | +### Pydantic V2 support |
| 22 | + |
| 23 | +If you are encountering issues with `pydantic>2`, it is most likely because you're using an old version of `pydantic-to-typescript`. |
| 24 | +Run `pip install 'pydantic-to-typescript>2'` and/or add `pydantic-to-typescript>=2` to your project requirements. |
| 25 | + |
| 26 | +### CI/CD |
| 27 | + |
| 28 | +You can now use `pydantic-to-typescript` to automatically validate and/or update typescript definitions as part of your CI/CD pipeline. |
| 29 | + |
| 30 | +The github action can be found here: https://github.com/marketplace/actions/pydantic-to-typescript. |
| 31 | +The available inputs are documented here: https://github.com/phillipdupuis/pydantic-to-typescript/blob/master/action.yml. |
18 | 32 |
|
19 | 33 | ### CLI
|
20 | 34 |
|
21 |
| -| Prop | Description | |
22 |
| -| :------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
23 |
| -| ‑‑module | name or filepath of the python module you would like to convert. All the pydantic models within it will be converted to typescript interfaces. Discoverable submodules will also be checked. | |
24 |
| -| ‑‑output | name of the file the typescript definitions should be written to. Ex: './frontend/apiTypes.ts' | |
25 |
| -| ‑‑exclude | name of a pydantic model which should be omitted from the resulting typescript definitions. This option can be defined multiple times, ex: `--exclude Foo --exclude Bar` to exclude both the Foo and Bar models from the output. | |
26 |
| -| ‑‑json2ts‑cmd | optional, the command used to invoke json2ts. The default is 'json2ts'. Specify this if you have it installed locally (ex: 'yarn json2ts') or if the exact path to the executable is required (ex: /myproject/node_modules/bin/json2ts) | |
| 35 | +| Prop | Description | |
| 36 | +| :------------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 37 | +| ‑‑module | name or filepath of the python module you would like to convert. All the pydantic models within it will be converted to typescript interfaces. Discoverable submodules will also be checked. | |
| 38 | +| ‑‑output | name of the file the typescript definitions should be written to. Ex: './frontend/apiTypes.ts' | |
| 39 | +| ‑‑exclude | name of a pydantic model which should be omitted from the resulting typescript definitions. This option can be defined multiple times, ex: `--exclude Foo --exclude Bar` to exclude both the Foo and Bar models from the output. | |
| 40 | +| ‑‑json2ts‑cmd | optional, the command used to invoke json2ts. The default is 'json2ts'. Specify this if you have it installed locally (ex: 'yarn json2ts') or if the exact path to the executable is required (ex: /myproject/node_modules/bin/json2ts) | |
27 | 41 |
|
28 | 42 | ---
|
29 | 43 |
|
|
0 commit comments