Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/grimmer0125/ts-json-schema

Use https://github.com/YousefED/typescript-json-schema 1. TypeScript -> Json Schema and 2. use ajv (master branch) / python jsonschema to import schema and invalidate json data.
https://github.com/grimmer0125/ts-json-schema

ajv typescript typescript-json-schema

Last synced: 7 days ago
JSON representation

Use https://github.com/YousefED/typescript-json-schema 1. TypeScript -> Json Schema and 2. use ajv (master branch) / python jsonschema to import schema and invalidate json data.

Awesome Lists containing this project

README

        

## TS-JSON-SCHEMA

## Prerequisite

1. Install yarn. https://yarnpkg.com/zh-Hans/
1. ~Install TypeScript globally [recommended way]. `yarn add global typescript`~
1. Execute `yarn` or `yarn install` in project root.

## In command line to use typescript-json-schema lib to generate json schema

`yarn run typescript-json-schema myString.ts MyString`

result in stdout, add `-o json.schema` to redirect to a file

## Test example.ts (master branch) to generate json scheman, and use AJV to validate (in js/ts), interface: myString.ts

1. Compile TypeScript to JavaScript, `yarn run build example.ts`
2. Test, `node example.js`, result in json.schema

## Test example.ts (bdd branch) to generate json schema, and use python to validate, interface: myObject.ts

1. `yarn run build example.ts`
2. `node example.js`
3. `pip install jsonschema`, it not installed
4. `python test.py` to validate