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

ts-json-schema-generator

Package Overview
Dependencies
Maintainers
3
Versions
335
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-json-schema-generator

Generate JSON schema from your Typescript sources

  • 2.3.0-next.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
99K
decreased by-59.82%
Maintainers
3
Weekly downloads
 
Created

What is ts-json-schema-generator?

The ts-json-schema-generator package is a tool that generates JSON schemas from TypeScript types. It is useful for ensuring that your TypeScript types and JSON schemas stay in sync, which can be particularly helpful for validating JSON data against TypeScript interfaces or types.

What are ts-json-schema-generator's main functionalities?

Generate JSON Schema from TypeScript Interface

This feature allows you to generate a JSON schema from a TypeScript interface. You need to specify the path to your TypeScript file and the type you want to generate the schema for.

const { createGenerator } = require('ts-json-schema-generator');
const config = {
  path: 'path/to/your/file.ts',
  tsconfig: 'path/to/your/tsconfig.json',
  type: '*', // Or specify a particular type
};
const schema = createGenerator(config).createSchema(config.type);
console.log(JSON.stringify(schema, null, 2));

Generate JSON Schema for Specific Type

This feature allows you to generate a JSON schema for a specific TypeScript type. You need to specify the path to your TypeScript file and the type you want to generate the schema for.

const { createGenerator } = require('ts-json-schema-generator');
const config = {
  path: 'path/to/your/file.ts',
  tsconfig: 'path/to/your/tsconfig.json',
  type: 'MyType', // Specify the type you want to generate the schema for
};
const schema = createGenerator(config).createSchema(config.type);
console.log(JSON.stringify(schema, null, 2));

Generate JSON Schema with Custom Settings

This feature allows you to generate a JSON schema with custom settings. You can specify various options such as exposing all types, referencing the top-level schema, and using extended JSDoc annotations.

const { createGenerator } = require('ts-json-schema-generator');
const config = {
  path: 'path/to/your/file.ts',
  tsconfig: 'path/to/your/tsconfig.json',
  type: 'MyType',
  expose: 'all', // Expose all types
  topRef: true, // Reference the top-level schema
  jsDoc: 'extended', // Use extended JSDoc annotations
};
const schema = createGenerator(config).createSchema(config.type);
console.log(JSON.stringify(schema, null, 2));

Other packages similar to ts-json-schema-generator

Keywords

FAQs

Package last updated on 25 May 2024

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