Skip to content

Repository files navigation

simple-tjscli

Download StatusGithub StarGithub IssuesNPM versionLicensesimple-tjscli

simple-tjscli is interactive cli tool for JSONSchema generation from TypeScript interface. simple-tjscli using two generator that YousefED/typescript-json-schema and vega/ts-json-schema-generator. You can select one tool after generate JSONSchema from TypeScript interface.

Only One Time 🙆

TypeScript interface convert to JSON schema.

exportinterfaceSong{/** * song name * @minLength 2 * @maxLength 256 * */name: string;/** * song length represent using second unit * @type integer * @maximum 1200 * */seconds: string;}

JSON schema generate from interface below,

{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": { "type": "string", "description": "song name", "minLength": 2, "maxLength": 256 },
"seconds": { "type": "string", "description": "song length represent using second unit", "maximum": 1200 }
},
"required": ["name", "seconds"]
}

Also You can create TypeScript variable like that(apply TypeScript template),

import{JSONSchema7}from'json-schema';constSong={$schema: 'http://json-schema.org/draft-07/schema#',type: 'object',properties: {name: {type: 'string',description: 'song name',minLength: 2,maxLength: 256},seconds: {type: 'string',description: 'song length represent using second unit',maximum: 1200},},required: ['name','seconds'],};exportdefaultSong;

Yes, simple-tjscli on counter part of json-schema-to-ts.

fastify.js

If you use fastify.js, simple-tjscli is a good parter to management of schemas. simple-tjscli generate definitions for addSchema function. So you define TypeScript interface after generate validation and @fastify/swagger. Yes, simple-tjscli is a one of option like fluent-json-schema, typebox, json-schema-to-ts

graph LR
A[TypeScript <br />interface] -->|simple-tjscli| B[JSON schema]
B -->|route| C[fastify.js]
C -->|ajv| D[validateion <br />Request/Response <br />DTO]
C -->|"@"fastify/swagger| E[Swagger.io <br />Documentation]
Loading

Only One conversion

Install

npm install simple-tjscli --save-dev

Usage

See below example.

# interfactive mode
$ npx tjscli tsj -i
# Pass file and type
$ npx tjscli tsj -f hello.ts -t IPrompt
# Watch mode
$ npx tjscli tsj-w --watch [watching directory]

Most case, interactive mode or watch mode satisfy your need. tjscli ask to you that interface file to convert JSONSchema.

Example Project

maeum is example project. maeum using simple-tjscli and fast-maker.

# Clone the boilerplate:
git clone --depth=1 \
https://github.com/imjuni/maeum \
your-project-name
cd your-project-name
npm install
# run simple-tjscli watch mode
npm run tjs-w

Options

nameshortcuttypegeneratordesc.
--cwd-wstringtsj, tjsworking directory
--config-cstringtsj, tjsconfiguration file path. example
--project-pstringtsj, tjstsconfig.json file path
--files-fstring[]tsj, tjstarget file
--types-tstring[]tsj, tjstarget type
--sync-sbooleantsj, tjssync mode, schema have same directory structure in input file
--interactive-ibooleantsj, tjsinteractive mode, ask input file and type
--noBanner-bbooleantsj, tjsno banner in generated schema
--output-ostringtsj, tjsoutput directory
--outputType-uenum('json', 'ts')tsj, tjsoutput schema type
--extName-estringtsj, tjsoutput file extension
--prefix-xstringtsj, tjsoutput file name prefix, ex> JSC -> JSC_IMajor.ts
--overwritestringtsj, tjsIf already exists schema file, overwrite schema
--templatestringtsj, tjstemplate string for output typescript file
--templatePathstringtsj, tjstemplate file path for output typescript file
--verbose-vbooleantsj, tjsverbose message
--watchstringtsjonly work in watch mode. watch directory
--debounceTimenumbertsjonly work in watch mode. watch file debounceTime. default 1000ms
--seperateDefinitionsbooleantsjcreate definitions.ts file using definitions value in generated json-schema
--skipTypeCheckbooleantsjts-json-schema-generator option
--topRefbooleantsjts-json-schema-generator option
--exposeenum('all', 'none', 'export')tsjts-json-schema-generator option
--jsDocenum('none', 'extended', 'basic')tsjts-json-schema-generator option
--extraTagsstring[]tsjts-json-schema-generator option
--additionalPropertiesbooleantsjts-json-schema-generator option

Programming Interface

functiondesc.
generateJSONSchemaUsingTSJgenerate json-schema using vega/ts-json-schema-generator
generateJSONSchemaUsingTJSgenerate json-schema using YousefED/typescript-json-schema
watchJSONSchemaUsingTSJwatch for generate json-schema using vega/ts-json-schema-generator

Releases

Packages

Used by

Contributors

Languages