Socket
Socket
Sign inDemoInstall

@env0/ts-transform-json-schema

Package Overview
Dependencies
57
Maintainers
5
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @env0/ts-transform-json-schema

Generate inline JSON schema from TypeScript types


Version published
Maintainers
5
Created

Readme

Source

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

Keywords

FAQs

Last updated on 06 Aug 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc