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

@hoth/typescript-to-json-schema

Package Overview
Dependencies
Maintainers
4
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hoth/typescript-to-json-schema

typescript to json-schema transpiler

  • 2.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by66.67%
Maintainers
4
Weekly downloads
 
Created
Source

typescript-to-json-schema

Language npm package Build Status

TypeScript to JsonSchema Transpiler

Usage

Programmatic use

import {resolve} from 'path';
import {generateSchema} from '@hoth/typescript-to-json-schema';

const {schemas} = generateSchema([resolve('demo.ts')]);

Annotations

For example

company.ts

import { integer } from "@hoth/typescript-to-json-schema";

type employee = {

    /**
     * 雇员名字
     *
     * @maxLength 50
     * @minLength 1
     */
    name: string;

    /**
     * 雇员年龄
     *
     * @minimum 18
     */
    age: integer;
};

interface Department {

    /**
     * 是否开始
     */
    open: boolean | null;

    /**
     * 员工
     *
     * @maxItems 1000
     */
    employee: employee[]
}

export interface Company {

    /**
     * 部门
     *
     * @minItems 1
     */
    departments: Department[]
}

output

    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "$id": "http://www.baidu.com/schemas/company.json",
      "$ref": "#/definitions/company",
      "definitions": {
        "department": {
          "type": "object",
          "properties": {
            "open": {
              "oneOf": [
                {
                  "type": "boolean"
                },
                {
                  "type": "null"
                }
              ],
              "description": "是否开始"
            },
            "employee": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/employee"
              },
              "maxItems": 1000,
              "description": "员工"
            }
          },
          "required": [
            "open",
            "employee"
          ]
        },
        "company": {
          "type": "object",
          "properties": {
            "departments": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/department"
              },
              "minItems": 1,
              "description": "部门"
            }
          },
          "required": [
            "departments"
          ]
        },
        "employee": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1,
              "maxLength": 50,
              "description": "雇员名字"
            },
            "age": {
              "type": "integer",
              "minimum": 18,
              "description": "雇员年龄"
            }
          },
          "required": [
            "name",
            "age"
          ]
        }
      }
    }

Keywords

FAQs

Package last updated on 28 Mar 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