0.0.2 • Published 6 years ago
@calmdownval/ts-schema v0.0.2
ts-schema: Type Safe JSON Schemas
This utility module provides an easy way to use JSON Schemas to ensure your input data is compatible with the TypeScript interfaces defined in your application.
Installation
npm install --save-dev @calmdownval/ts-schema
Usage
Usage: ts-schema [options] <files>
Options:
--help Show help
--version Show version number
--engine which JSON Schema engine to use
--out output TS file path
Files should be a list of paths or glob patterns. The utility expects exactly one TypeScript interface in each file matched. It is recommended to clearly mark these files as schemas for this tool to work as intended. Some good ways of keeping track are for example:
- Have a
/schemas
folder with all the interface definitions (one per file) in it.
Call the tool withts-schema "./src/schemas/*.ts"
- Identify schema interfaces with a filename suffix
<name>.schema.ts
Call the tool withts-schema "./src/**/*.schema.ts"
Running the utility will first auto-generate JSON Schema files and store them alongside the input files. Later a TypeScript file will be generated with validation functions for each interface.
ToDo
- $ref support