generate-it-typegen-spec2ts
v1.0.1
Published
A schema to TypeScript generator plugin for generate-it wrapping @spec2ts/jsonschema
Downloads
6
Maintainers
Readme
Generate-It TypeGen Spec2TS
A schema to TypeScript generator plugin for generate-it acting as a thin wrapper around the @spec2ts/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 forunions
); - supports and generates proper
nullable
properties (quicktype does not respect thenullable
parameter at the time of writing);
Usage
In your generate-it managed project do the following:
npm install --save-dev generate-it-typegen-spec2ts
Afterwards make sure you modify your .nodegenrc
file to look like this:
{
// ...
// 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.