Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maasglobal/io-ts-from-json-schema
Iotsfjs is a static code generation utility used for converting json schema files into io-ts runtime validators.
https://github.com/maasglobal/io-ts-from-json-schema
Last synced: 12 days ago
JSON representation
Iotsfjs is a static code generation utility used for converting json schema files into io-ts runtime validators.
- Host: GitHub
- URL: https://github.com/maasglobal/io-ts-from-json-schema
- Owner: maasglobal
- License: mit
- Created: 2020-05-15T10:15:08.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-10-17T06:29:27.000Z (about 1 year ago)
- Last Synced: 2024-09-16T23:10:20.707Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 927 KB
- Stars: 32
- Watchers: 2
- Forks: 9
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# io-ts-from-json-schema
Iotsfjs is a static code generation utility used for converting [json schema](https://json-schema.org/) files into static [TypeScript](https://www.typescriptlang.org/) types and [io-ts](https://github.com/gcanti/io-ts) runtime validators.
## Basic Use
```Shell
npm install -g io-ts-from-json-schema typescript
iotsfjs --inputFile schema.json --outputDir output
```## Usage Example
```Shell
# 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/
```