https://github.com/zewish/generate-it-typegen-spec2ts
A schema to TypeScript generator plugin for generate-it acting as a thin wrapper around the @spec2ts/jsonschema type generator.
https://github.com/zewish/generate-it-typegen-spec2ts
Last synced: 8 months ago
JSON representation
A schema to TypeScript generator plugin for generate-it acting as a thin wrapper around the @spec2ts/jsonschema type generator.
- Host: GitHub
- URL: https://github.com/zewish/generate-it-typegen-spec2ts
- Owner: zewish
- License: mit
- Created: 2022-11-23T16:41:36.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-11-23T17:22:21.000Z (over 3 years ago)
- Last Synced: 2025-10-19T16:01:11.271Z (8 months ago)
- Language: TypeScript
- Homepage:
- Size: 161 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/generate-it-typegen-spec2ts)
[](https://github.com/zewish/generate-it-typegen-spec2ts/actions?query=workflow%3Abuild)
[](https://coveralls.io/github/zewish/generate-it-typegen-spec2ts?branch=master)
[](https://www.npmjs.com/package/generate-it-typegen-spec2ts)
# Generate-It TypeGen Spec2TS
A schema to TypeScript generator plugin for [generate-it](https://github.com/acr-lfr/generate-it) acting as a thin wrapper around the [@spec2ts/jsonschema](https://github.com/touchifyapp/spec2ts/tree/master/packages/jsonschema) type generator.
## Motivation
Since version 5.42.0 generate-it supports using external schema to type generation plugins which effectively overrides the default integrated type generator (quicktype).
The @spec2ts/jsonschema package is clean-slate TypeScript-only solution which generates better types than the current solution used internally in generate-it. Compared to the default type generator this typegen has the following improvements:
- generates proper date types (quicktype only generates `string` for the "type: date-time" fields at the time of writing);
- always creates unions instead of the non-interchangeable enum types (quicktype generates `enums` by default, has an optional flag for `unions`);
- supports and generates proper `nullable` properties (quicktype does not respect the `nullable` parameter at the time of writing);
## Usage
In your generate-it managed project do the following:
```sh
npm install --save-dev generate-it-typegen-spec2ts
```
Afterwards make sure you modify your `.nodegenrc` file to look like this:
```jsonc
{
// ...
// required:
"typegen": "generate-it-typegen-spec2ts",
// optionally override default typegen options (defaults are given here for reference):
"typegenOptions": {
"avoidAny": false,
"enableDate": true
}
}
```
Finally make sure to regenerate your project.
**NOTE: In case this is an existing project you may need to do some fixes on your exsiting types in the project.**