npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-tjscli

v1.2.0

Published

Create JSONSchema from typescript interface using creation engine

Downloads

105

Readme

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

| name | shortcut | type | generator | desc. | | ---------------------- | -------- | :-------------------------------: | :-------: | :------------------------------------------------------------------------------------------------- | | --cwd | -w | string | tsj, tjs | working directory | | --config | -c | string | tsj, tjs | configuration file path. example | | --project | -p | string | tsj, tjs | tsconfig.json file path | | --files | -f | string[] | tsj, tjs | target file | | --types | -t | string[] | tsj, tjs | target type | | --sync | -s | boolean | tsj, tjs | sync mode, schema have same directory structure in input file | | --interactive | -i | boolean | tsj, tjs | interactive mode, ask input file and type | | --noBanner | -b | boolean | tsj, tjs | no banner in generated schema | | --output | -o | string | tsj, tjs | output directory | | --outputType | -u | enum('json', 'ts') | tsj, tjs | output schema type | | --extName | -e | string | tsj, tjs | output file extension | | --prefix | -x | string | tsj, tjs | output file name prefix, ex> JSC -> JSC_IMajor.ts | | --overwrite | | string | tsj, tjs | If already exists schema file, overwrite schema | | --template | | string | tsj, tjs | template string for output typescript file | | --templatePath | | string | tsj, tjs | template file path for output typescript file | | --verbose | -v | boolean | tsj, tjs | verbose message | | --watch | | string | tsj | only work in watch mode. watch directory | | --debounceTime | | number | tsj | only work in watch mode. watch file debounceTime. default 1000ms | | --seperateDefinitions | | boolean | tsj | create definitions.ts file using definitions value in generated json-schema | | --skipTypeCheck | | boolean | tsj | ts-json-schema-generator option | | --topRef | | boolean | tsj | ts-json-schema-generator option | | --expose | | enum('all', 'none', 'export') | tsj | ts-json-schema-generator option | | --jsDoc | | enum('none', 'extended', 'basic') | tsj | ts-json-schema-generator option | | --extraTags | | string[] | tsj | ts-json-schema-generator option | | --additionalProperties | | boolean | tsj | ts-json-schema-generator option |

Programming Interface

| function | desc. | | -------------------------- | ---------------------------------------------------------------------------------------------------------------------- | | generateJSONSchemaUsingTSJ | generate json-schema using vega/ts-json-schema-generator | | generateJSONSchemaUsingTJS | generate json-schema using YousefED/typescript-json-schema | | watchJSONSchemaUsingTSJ | watch for generate json-schema using vega/ts-json-schema-generator |