Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anderscan/teason
https://github.com/anderscan/teason
Last synced: 15 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/anderscan/teason
- Owner: AndersCan
- Created: 2019-05-22T14:11:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-02T19:35:33.000Z (about 1 year ago)
- Last Synced: 2024-10-23T08:24:39.964Z (2 months ago)
- Language: TypeScript
- Size: 302 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# teason - it's teason then
`teason` is a cli that takes **T**ypeScript definitions and generates both J**SON** schema and JSON mock data.
~~Some might call it a **TSON** generator~~
## Examples
Take a look at the examples to understand what `teason` does
Examples can be found in [the /examples directory](/examples)
## How to use
`npm i teason`
After installing you will be able to run the command `npx teason --help`
### cli options
Teason requires two things to run
1. Folder path where the TypeScript definitions can be found
2. The interface name to use> Not defining `output-paths` will result in no output (a dry-run)
> Changing `validation-keywords` will remove the default value (`faker`)
```bash
Options:
-t, --types-folder folder path with typescript types
-i, --interface-name main interface to begin with
-j, --json-output-path output file to store the generated JSON
-s, --schema-output-path output file to store the generated Schema
-v, --validation-keywords keywords of extra annotation to accept ex: "title,test,data" (default: ["faker"])
-h, --help output usage information
```### config options
You can also store your config in a `.teasonrc` file
```json
{
"typesFolder": "types",
"interfaceName": "Database",
"jsonOutputPath": "out.json",
"schemaOutputPath": "out.schema.json",
"validationKeywords": ["faker"]
}
```## Schema
The schema output can be used to validate or create new JSON data.
[validation with ajv](https://github.com/epoberezkin/ajv) and/or
[creating with json-editor github](https://json-editor.github.io/json-editor/)## Mock data
Mock data that conforms to your schema. Can be extended with `@faker` annotations to create more realistic data
Uses [typescript-json-schema](https://github.com/YousefED/typescript-json-schema), [json-schema-faker](https://github.com/json-schema-faker/json-schema-faker/) and [faker.js](https://marak.github.io/faker.js/) under the hood.
### json-server
The output from `teason` is not optimized for [json-server](https://github.com/typicode/json-server), but it can be done quite easily.
The quickest way is to use [normalizr](https://github.com/paularmstrong/normalizr) and define a [`normalizr.schema`](https://github.com/paularmstrong/normalizr/blob/master/docs/api.md#schema) (not to be confused with a json schema).
[/examples/post-process.ts](/examples/post-process.ts) contains what you need. In most cases you will only have to change the result of `getDbSchema()` to get the script working for you