@ts-to-json-schema/core
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

@ts-to-json-schema/core

Core functions for TypeScript to JSON Schema

Installation

npm install @ts-to-json-schema/core
npm install --save-dev typescript @ts-to-json-schema/transform ts-patch

Configuration

{
  "compilerOptions": {
    // ...
    "plugins": [
      { "transform": "@ts-to-json-schema/compiler", "type": "program" }
    ]
  }
}

Obs: Follow the instructions in the @ts-to-json-schema/transform to configure in your bundler.

Usage

import { toJsonSchema } from "@ts-to-json-schema/core";

interface MyType {
  foo: string;
  bar?: number;
}

const schema = toJsonSchema<MyType>();

console.log(schema);

/*
* Output:
* {
*   type: 'object',
*   properties: {
*     foo: { type: 'string' },
*     bar: { type: 'number' }
*   },
*   required: ['foo']
* }
 */

Package Sidebar

Install

npm i @ts-to-json-schema/core

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

3.99 kB

Total Files

6

Last publish

Collaborators

  • pedromdev