Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

create-ts-json-schema

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-ts-json-schema

generate json-schema from typescript source code and management it

  • 0.11.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

create-ts-json-schema

Download Status Github Star Github Issues NPM version License

automatically generate json-schema from TypeScript source code and management it!

What is create-ts-json-schema?

create-ts-json-schema is tiny cli utility that automatically generate json-schema from TypeScript source code and management generated json-schema. If you use fastify.js that uses json-schema to validate request and reply. But managing a large number of json-schema takes a lot of effort. create-ts-json-schema help that work.

demo

installation

npm install create-ts-json-schema --save-dev

Usage

# generate json-schema and create database (if exist)
ctjs add

# delete json-schema from database
ctjs del

# truncate database
ctjs truncate

# regenerate all json-schema in database

Fastify.js

Example for fastify

import fastify from 'fastify';
import fs from 'fs';

const server = fastify();
const db = JSON.parse((await fs.promises.readFile('db.json')).toString());
Object.value(db).forEach((record) => server.addSchema(JSON.parse(record.schema)));

server.get(
  '/pokemon/:name',
  {
    schema: {
      tags: ['Pokemon'],
      summary: 'Pokemon detail information using by name',
      querystring: { $ref: 'IReqPokeDetailQuerystring' }, // You can access local reference for fastify schema store
      params: { $ref: 'IReqPokeDetailParams' }, // You can access local reference for fastify schema store
      response: {
        200: { $ref: 'IPokemonDto' }, // You can access local reference for fastify schema store
      },
    },
  },
  (req) => {
    /* your handler code */
  },
);

command and option

command

commandaliasdescription
addaadd or update json-schema to database file
delddelete json-schema from database file
refreshrregenerate all json-schema in database file
truncatetreset database file

add option

optionaliasdescription
projectptsconfig.json path
configcconfiguration file path
outputodatabase file path
skip-errorskip compile error on source file
typesTypeScript type of source code. You can use interface, type alias, enum, class.
filesTypeScript source code file path
formatgenerated json-schema save format: json, string, base64

delete option

optionaliasdescription
projectptsconfig.json path
configcconfiguration file path
outputodatabase file path
skip-errorskip compile error on source file
typesTypeScript type of source code. You can use interface, type alias, enum, class.
filesTypeScript source code file path

refresh option

optionaliasdescription
projectptsconfig.json path
configcconfiguration file path
outputodatabase file path
skip-errorskip compile error on source file
formatgenerated json-schema save format: json, string, base64

truncate option

optionaliasdescription
projectptsconfig.json path
configcconfiguration file path
outputodatabase file path

FAQs

Package last updated on 16 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc