1.0.1 • Published 1 year ago

generate-it-typegen-spec2ts v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

NPM Version Build Status Coverage Status NPM Downloads

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 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:

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.