0.0.26 • Published 9 months ago

io-ts-from-json-schema v0.0.26

Weekly downloads
13
License
MIT
Repository
github
Last release
9 months ago

io-ts-from-json-schema

Iotsfjs is a static code generation utility used for converting json schema files into static TypeScript types and io-ts runtime validators.

Basic Use

npm install -g io-ts-from-json-schema typescript
iotsfjs --inputFile schema.json --outputDir output

Usage Example

# Create a Project
mkdir example && cd example
npm init -f && npm install --peer fp-ts io-ts io-ts-types

# Create a Schema File
npm install --peer maas-schemas-ts
mkdir -p ./schemas/examples && echo '{
  "$id": "http://example.com/iotsfjs/examples/user.json",
  "description": "Example user schema with an external dependency",
  "type": "object",
  "definitions": {
    "name": {
      "description": "Human-readable name of the user",
      "type": "string"
    }
  },
  "properties": {
    "name": {
      "$ref": "#/definitions/name"
    },
    "phone": {
      "$ref": "http://maasglobal.com/core/components/common.json#/definitions/phone"
    }
  },
  "required": ["name", "phone"],
  "additionalProperties": false,
  "examples": [
    {
      "name": "Joe User",
      "phone": "+358407654321"
    }
  ]
}' > ./schemas/examples/user.json

# Generate TypeScript Code
npm install --dev io-ts-from-json-schema typescript
./node_modules/.bin/iotsfjs --inputFile 'schemas/**/*.json' --outputDir src --base http://example.com/iotsfjs/ --import http://maasglobal.com/^maas-schemas-ts/lib/

# Generate Tests
npm install --dev jest @types/jest doctest-ts ts-jest io-ts-validator maas-schemas-ts fp-ts io-ts io-ts-types
./node_modules/.bin/ts-jest config:init
./node_modules/.bin/doctest-ts --jest `find src -name '*.ts'`

# Run Tests
./node_modules/.bin/jest --testPathPattern --testMatch **/*.doctest.ts --roots src/

# Compile TypeScript Code
./node_modules/.bin/tsc -d --rootDir src src/examples/user.ts --outDir lib/
0.0.26

9 months ago

0.0.24

11 months ago

0.0.25

9 months ago

0.0.26-alpha1

9 months ago

0.0.25-alpha1

11 months ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.22-alpha1

1 year ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.20-alpha2

2 years ago

0.0.20-alpha7

2 years ago

0.0.20-alpha3

2 years ago

0.0.20-alpha4

2 years ago

0.0.20-alpha5

2 years ago

0.0.20-alpha6

2 years ago

0.0.20-alpha1

3 years ago

0.0.19

3 years ago

0.0.19-alpha1

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.13-alpha6

4 years ago

0.0.13-alpha2

4 years ago

0.0.13-alpha1

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.10-alpha2

4 years ago

0.0.10-alpha1

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.7-alpha1

4 years ago

0.0.6

4 years ago

0.0.6-alpha3

4 years ago

0.0.6-alpha2

4 years ago

0.0.6-alpha1

4 years ago

0.0.5

4 years ago

0.0.5-alpha1

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago