npm
Spec TypeScript code generation is packaged in form of npm package. Add following dependency to your project:
The has specgen command line tool is built inside of the npm package.
Add the following script to package.json
:
In this specgen
script <command>
stands for specific specgen tool command. Here are commands that generate TypeScript code: service-ts
, client-ts
, models-ts
.
To run code generation execute specgen
script:
This page provides some examples of specgen scripts configuration.
Express Service
The example below generates Express server with Superstruct models to ./src/spec
and OpenAPI specification to ./docs/swagger.yaml
. The command also scaffolds services (only if they don't exist yet) that should be implemented by developers and puts the code into ./src/services
path.
Read service-ts
documentation for command details.
Koa Service
The example below generates koa server with io-ts models to ./src/spec
and OpenAPI specification to ./docs/swagger.yaml
. The command also scaffolds services (only if they don't exist yet) that should be implemented by developers and puts the code into ./src/services
path.
Read service-ts
documentation for command details.
Axios Client
The example below generates Axios HTTP client with Superstruct models from ./spec.yaml
speicification and puts generated code to ./src/spec
.
Read client-ts
documentation for command details.
Superstruct Models
The example below generates Superstruct models from ./spec.yaml
speicification and puts generated code to ./src/spec
.
Read models-ts
documentation for command details.
io-ts Models
The example below generates io-ts models from ./spec.yaml
speicification and puts generated code to ./src/spec
.
Read models-ts
documentation for command details.
Last updated