typescript-to-jsonschema generates JSON Schema files from your Typescript sources.

Overview

fast-typescript-to-jsonschema

npm version Test codecov

English | 简体中文

a tool generate json schema from typescript.

Feature

  • compile Typescript to get all type information
  • convert properties, extends, annotations, and initial values to jsonschema

Usage

  1. install
yarn add fast-typescript-to-jsonschema -D
  1. create type.ts
interface ITest {
  attr1: string;
  attr2: number;
  attr3?: boolean;
}
  1. create test.js
const { default: genTypeSchema } = require('fast-typescript-to-jsonschema');
const path = require('path');

// target file
const file = path.resolve(__dirname, './type.ts');

// generate data
genTypeSchema.genJsonDataFormFile(file);

// get all jsonschema data of current file
const json = genTypeSchema.genJsonData();

// get jsonschema of specific type
const jsonSchema = genTypeSchema.getJsonSchema(file, 'ITest');

// result
console.log(jsonSchema); 
  1. execute script
node ./test.js

jsonSchema result:

{
  "additionalProperties": false,
  "properties": {
    "attr1": {
      "type": "string",
    },
    "attr2": {
      "type": "number",
    },
    "attr3": {
      "type": "boolean",
    },
  },
  "required": [
    "attr1",
    "attr2",
  ],
  "type": "object",
}

see more examples at example.

Comments

Example1

interface Interface_1 {
  attr: string;
}

result:

{
  "additionalProperties": false,
  "properties": {
    "attr": {
      "type": "string",
    },
  },
  "required": [
    "attr",
  ],
  "type": "object",
}

Example2

interface Interface_4 {
  attr: string[];
}

result:

{
  "additionalProperties": false,
  "properties": {
    "attr": {
      "items": {
        "type": "string",
      },
      "type": "array",
    },
  },
  "required": [
    "attr",
  ],
  "type": "object",
}

Read more supported types here

Contribution

Contributions are extremely welcomed by our team, you can contribute to this repository by several ways below.

You might also like...

Here are the sources for the wdi5 workshop at UI5con 2022.

wdi5 workshop at UI5con 2022 Here are the sources for the wdi5 workshop at UI5con 2022. prerequisites please have this installed on your 'puter: Node

Oct 19, 2022

In this project, I built a simple HTML list of To-Do tasks. Using webpack to bundle JS functionality and other sources.

To-do-list App A simple To-do-list app using DOM manipulation. Built With HTML/CSS JavaScript Webpack Jest Live Demo Live Demo Getting Started Get a c

Nov 5, 2022

Merge multiple Prisma schema files, model inheritance, resolving name conflicts and timings reports, all in a simple tool.

Prisma Util What is Prisma Util? • How to use? • The configuration file • Support What is Prisma Util? Prisma Util is an easy to use tool that merges

Dec 28, 2022

A script that combines a folder of SVG files into a single sprites file and generates type definitions for safe usage.

remix-sprites-example A script that combines a folder of .svg files into a single sprites.svg file and type definitions for safe usage. Technical Over

Nov 9, 2022

This package generates a GraphQL API from a directory of Markdown files

This package generates a GraphQL API from a directory of Markdown files. Additional metadata like tags, descriptions, or custom fields can be added to the Markdown files in the form of YAML front matter, a simple schema at the top of each file. These fields will be indexed and available to query and filter by in the GraphQL API.

Dec 29, 2022

JSON Visio is data visualization tool for your json data which seamlessly illustrates your data on graphs without having to restructure anything, paste directly or import file.

JSON Visio is data visualization tool for your json data which seamlessly illustrates your data on graphs without having to restructure anything, paste directly or import file.

JSON Visio is data visualization tool for your json data which seamlessly illustrates your data on graphs without having to restructure anything, paste directly or import file.

Jan 4, 2023

Pretty-print-json - 🦋 Pretty-print JSON data into HTML to indent and colorize (written in TypeScript)

Pretty-print-json - 🦋 Pretty-print JSON data into HTML to indent and colorize (written in TypeScript)

pretty-print-json Pretty-print JSON data into HTML to indent and colorize (written in TypeScript) 1) Try It Out Interactive online tool to format JSON

Dec 30, 2022

Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator Types generator is a utility tool that will help User to create TS Interfaces from JSON. All you have to do is paste your single objec

Dec 6, 2022

Opinionated collection of TypeScript definitions and utilities for Deno and Deno Deploy. With complete types for Deno/NPM/TS config files, constructed from official JSON schemas.

Opinionated collection of TypeScript definitions and utilities for Deno and Deno Deploy. With complete types for Deno/NPM/TS config files, constructed from official JSON schemas.

Schemas Note: You can also import any type from the default module, ./mod.ts deno.json import { type DenoJson } from "https://deno.land/x/[email protected]

Oct 12, 2022
Releases(v0.06)
  • v0.06(Sep 29, 2022)

  • v0.0.5(May 24, 2022)

    What's Changed

    • fix: 完善重复引用逻辑 by @HUxiaoAlinNG in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/18
    • fix: namespace 多层嵌套解析问题 by @HUxiaoAlinNG in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/18

    Full Changelog: https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/compare/v0.0.4...v0.0.5

    Source code(tar.gz)
    Source code(zip)
  • v0.0.4(May 19, 2022)

    What's Changed

    • docs(readme): fix jump link between different languages by @lexmin0412 in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/16
    • 枚举类型解析问题 by @HUxiaoAlinNG in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/17
    • 完善解析不同文件引用类型的逻辑 by @HUxiaoAlinNG in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/17

    Full Changelog: https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/compare/v0.0.3...v0.0.4

    Source code(tar.gz)
    Source code(zip)
  • v0.0.3(Mar 23, 2022)

    What's Changed

    • Add English docs by @lexmin0412 in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/13
    • 支持工具函数Required/Partial by @HUxiaoAlinNG in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/14
    • feat: 默认文档切换为英文文档 by @wangweianger in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/15

    New Contributors

    • @lexmin0412 made their first contribution in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/13

    Full Changelog: https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/compare/v0.0.2...v0.0.3

    Source code(tar.gz)
    Source code(zip)
  • v0.0.2(Mar 21, 2022)

    What's Changed

    • feat: enable sourcemap by @wangweianger in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/8
    • docs: 更正 example 案例地址链接 by @xjq7 in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/9
    • 完善逻辑,增加type数组内引用类型解析 by @HUxiaoAlinNG in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/10
    • feat: 完善additionalProperties处理,补充测试用例 by @HUxiaoAlinNG in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/11
    • 增加Pick/Omit对type 联合类型的支持 by @HUxiaoAlinNG in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/12

    Full Changelog: https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/compare/v0.0.1...v0.0.2

    Source code(tar.gz)
    Source code(zip)
  • v0.0.1(Mar 10, 2022)

    What's Changed

    • docs: 1. 修复模块链接 2. 贡献文案修改 by @xjq7 in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/1
    • docs: 更新使用文档,删除gitlab-ci,更改package.name by @HUxiaoAlinNG in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/2
    • 优化文档,新增测试流水配置 by @wangweianger in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/3
    • feat: 文档优化 by @wangweianger in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/4
    • feat: add license by @wangweianger in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/5
    • fix: genJsonschema 方法 entry 增加默认值处理 by @xjq7 in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/6
    • 修复包名 by @wangweianger in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/7

    New Contributors

    • @xjq7 made their first contribution in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/1
    • @HUxiaoAlinNG made their first contribution in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/2
    • @wangweianger made their first contribution in https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pull/3

    Full Changelog: https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/commits/v0.0.1

    Source code(tar.gz)
    Source code(zip)
Owner
yunfly
Node.js开源框架
yunfly
Validate your Markdown frontmatter data against a JSON schema — remark-lint rule plugin

remark-lint-frontmatter-schema Validate Markdown frontmatter YAML against an associated JSON schema with this remark-lint rule plugin. Supports: Types

Julian Cataldo 20 Dec 10, 2022
JCS (JSON Canonicalization Scheme), JSON digests, and JSON Merkle hashes

JSON Hash This package contains the following JSON utilties for Deno: digest.ts provides cryptographic hash digests of JSON trees. It guarantee that d

Hong Minhee (洪 民憙) 13 Sep 2, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
Add aliasing support to Vite from tsconfig.json or jsconfig.json files

Config to Alias Config to Alias adds aliasing support to Astro, JavaScript, TypeScript, and CSS files. Usage Install Config to Alias. npm install @ast

Astro Community 4 Mar 17, 2023
Piplup: decompile Playdate Pulp .pdx files back to .json project files

Piplup: decompile Playdate Pulp .pdx files back to .json project files This doesn't work yet: I still need to: convert the graphics (.pdt files) back

null 6 Mar 25, 2022
Validate directory structure and file contents with an extension of JSON schema.

directory-schema-validator Description Validate directory structure and file contents with an extension of JSON schema. Install Install using NPM or s

Justin Poehnelt 5 Nov 1, 2022
Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.

JSON Form The JSON Form library is a JavaScript client-side library that takes a structured data model defined using JSON Schema as input and returns

null 2.6k Dec 28, 2022
A set of connectors to describe, parse and process the data sources provided by websites and social networks

HUDI-PACKAGE-CONNECTORS What is this repository for? A set of connectors to describe, parse and process the data sources provided by websites and soci

HUDI 8 Aug 5, 2022
11ty starter: uses md and notion as data sources

eleventy_notion_starter 11ty starter: uses md and notion as data sources. Based on https://github.com/siakaramalegos/11ty-sia-blog. Used to power http

Thiago Margarida 18 Oct 26, 2022
Python based web application to import, connect and analyze manufacturing data from multiple data sources.

Analysis Platform Analysis Platform is an open source web application to import, connect and visualize factory IoT data. It helps to collect, link and

Analysis Platform +DN7 7 Dec 1, 2022