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

2.0.8 • Public • Published

ts-transform-json-schema

  • 🌳 Generate inline JSON schema from TypeScript types

Example

In

import * as JsonSchema from "ts-transform-json-schema";

export interface SomeInterface {
  a: string;
  b: number;
  c?: boolean;
}

export const schema = JsonSchema.fromType<SomeInterface>({
  additionalProperties: false
});
// tsconfig.json
{
  "compilerOptions": {
    "target": "es2015",
    "plugins": [
      {
        "transform": "ts-transform-json-schema",
        "type": "program"
      }
    ]
  }
}

Out

import * as JsonSchema from "ts-transform-json-schema";
export const schema = {
  additionalProperties: false,
  type: "object", 
  properties: { 
    a: { type: "string" }, 
    b: { type: "number" }, 
    c: { type: "boolean" } 
  }, 
  $schema: "http://json-schema.org/draft-07/schema#" 
};

Installation

npm install ts-transform-json-schema ttypescript --save-dev

Usage

// tsconfig.json
{
  "compilerOptions": {
    "target": "es2015",
    "plugins": [
      {
        "transform": "ts-transform-json-schema",
        "type": "program"
      }
    ]
  }
}

See TTypeScript for docs about integration with other toolchains.


See ./example for a basic setup based on TTypeScript

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @env0/ts-transform-json-schema

Weekly Downloads

2

Version

2.0.8

License

MIT

Unpacked Size

14.7 kB

Total Files

25

Last publish

Collaborators

  • liron-env0
  • botenv0
  • eranelbaz
  • away168
  • razbensimon
  • roni-frantchi
  • omryhay
  • arelenv0
  • yaron-env0
  • avnerenv0
  • yossi-kerner
  • heverfarber.env0