Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Compile JSONSchema to TypeScript type declarations

NotificationsYou must be signed in to change notification settings

ProgrammerHuang/json-schema-to-typescript

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Circle CI

Compile json schema to typescript typings

Example

Input:

{"title":"Example Schema","type":"object","properties": {"firstName": {"type":"string"    },"lastName": {"type":"string"    },"age": {"description":"Age in years","type":"integer","minimum":0    }  },"required": ["firstName","lastName"]}

Output:

interfaceExampleSchema{firstName:string;lastName:string;age?:number;// Age in years}

Installation

npm install json-schema-to-typescript

Usage

import{compileFromFile}from'json-schema-to-typescript'fs.writeFileSync('foo.d.ts',awaitcompileFromFile('foo.json'))

Tests

npm test

Todo

  • title =>interface
  • Primitive types:
    • array
    • array of type
    • boolean
    • integer
    • number
    • null
    • object
    • string
    • enum
  • Non/extensible interfaces
  • Custom JSON-schema extensions
  • Nested properties
  • Schema definitions
  • Schema references
  • External (network) schema references
  • Add support for running in browser
  • default interface name
  • infer unnamed interface name from filename
  • oneOf ("xor")
  • anyOf ("union")
  • allOf ("intersection")
  • additionalProperties of type
  • extends
  • required properties on objects (eg)
  • validateRequired (eg)
  • literal objects in enum (eg)
  • referencing schema by id (eg)

Not expressible in TypeScript:

Further Reading

About

Compile JSONSchema to TypeScript type declarations

Resources

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript99.9%
  • JavaScript0.1%

[8]ページ先頭

©2009-2025 Movatter.jp