1.2.0 • Published 2 years ago

simple-tjscli v1.2.0

Weekly downloads
65
License
MIT
Repository
github
Last release
2 years ago

simple-tjscli

Download Status Github Star Github Issues NPM version License simple-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.

export interface Song {
  /**
   * 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';

const Song = {
  $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'],
};

export default Song;

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]

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
1.2.0

2 years ago

1.1.1

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.6

2 years ago

1.0.4

2 years ago

1.1.2

2 years ago

1.0.3

2 years ago

1.0.0-beta2

2 years ago

1.1.0-beta01

2 years ago

1.0.0-beta

2 years ago

1.1.0-beta

2 years ago

0.12.0

2 years ago

0.11.2

2 years ago

0.11.0

3 years ago

0.11.1

3 years ago

0.10.2

3 years ago

0.10.1

3 years ago

0.10.0

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.5.5

4 years ago

0.6.0

4 years ago

0.5.4

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago