specgen
  • Introduction
  • spec
    • Format Overview
    • Types
    • Models
    • HTTP Endpoints
  • specgen
    • Overview
    • Specgen Reference
    • Plugins
      • gradle
      • Maven
      • npm
      • Sbt
      • RAKE
Powered by GitBook
On this page
  • Express Service
  • Koa Service
  • Axios Client
  • Superstruct Models
  • io-ts Models
  1. specgen
  2. Plugins

npm

PreviousMavenNextSbt

Last updated 3 years ago

Spec TypeScript code generation is packaged in form of npm package. Add following dependency to your project:

% npm install --dev specgen.io

The has specgen command line tool is built inside of the npm package.

Add the following to package.json:

"specgen": "specgen <command>  <args>"

In this specgen script <command> stands for specific command. Here are commands that generate TypeScript code: , , .

To run code generation execute specgen script:

% npm run specgen

This page provides some examples of specgen scripts configuration.

Express Service

The example below generates server with 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.

"specgen": "specgen service-ts --server express --validation superstruct --spec-file ./spec.yaml --generate-path ./src/spec --swagger-path ./docs/swagger.yaml --services-path ./src/services"

Read documentation for command details.

Koa Service

The example below generates server with 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.

"specgen": "specgen service-ts --server koa --validation io-ts --spec-file ./spec.yaml --generate-path ./src/spec --swagger-path ./docs/swagger.yaml --services-path ./src/services"

Axios Client

"specgen": "specgen client-ts --client axios --validation superstruct --spec-file ./spec.yaml --generate-path ./src/spec"

Superstruct Models

"specgen": "specgen models-ts --validation superstruct --spec-file ./spec.yaml --generate-path ./src/spec"

io-ts Models

"specgen": "specgen models-ts --validation io-ts --spec-file ./spec.yaml --generate-path ./src/spec"

Read documentation for command details.

The example below generates HTTP client with models from ./spec.yaml speicification and puts generated code to ./src/spec.

Read documentation for command details.

The example below generates models from ./spec.yaml speicification and puts generated code to ./src/spec.

Read documentation for command details.

The example below generates models from ./spec.yaml speicification and puts generated code to ./src/spec.

Read documentation for command details.

Axios
Superstruct
Superstruct
io-ts
script
specgen tool
Express
Superstruct
koa
io-ts
service-ts
client-ts
models-ts
service-ts
service-ts
client-ts
models-ts
models-ts