GithubHelp home page GithubHelp logo

adrienjoly / mongodb-json-schema-to-typescript Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bcherny/json-schema-to-typescript

4.0 2.0 0.0 4.1 MB

Compile MongoDB JSON Schema to TypeScript typings

TypeScript 99.89% JavaScript 0.11%

mongodb-json-schema-to-typescript's Introduction

** NOT MAINTAINED -- PLEASE DO NOT USE **

(for more context, see signaux-faibles/opensignauxfaibles#317)

mongodb-json-schema-to-typescript

Transform MongoDB-compliant JSON Schema files to TypeScript.

On top of json-schema-to-typescript, it supports bsonType values, including date.

This fork also supports some bsonType types: Date or fallback to usual values for type.

Example

Input:

{
  "title": "Example Schema",
  "bsonType": "object",
  "properties": {
    "name": {
      "bsonType": "string"
    },
    "subscriptionDate": {
      "bsonType": "date"
    },
    "age": {
      "description": "Age in years",
      "bsonType": "integer",
      "minimum": 0
    },
    "hairColor": {
      "enum": ["black", "brown", "blue"],
      "bsonType": "string"
    }
  },
  "additionalProperties": false,
  "required": ["name", "subscriptionDate"]
}

Output:

export interface ExampleSchema {
  name: string;
  subscriptionDate: Date;
  /**
   * Age in years
   */
  age?: number;
  hairColor?: "black" | "brown" | "blue";
}

CLI

A CLI utility is provided with this package.

npx mongodb-json-schema-to-typescript foo.json > foo.d.ts

Tests

npm test

Features

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

Custom schema properties:

  • tsType: Overrides the type that's generated from the schema. Useful for forcing a type to any or when using non-standard JSON schema extensions (eg).
  • tsEnumNames: Overrides the names used for the elements in an enum. Can also be used to create string enums (eg).

Not expressible in TypeScript:

FAQ

JSON-Schema-to-TypeScript is crashing on my giant file. What can I do?

Prettier is known to run slowly on really big files. To skip formatting and improve performance, set the format option to false.

Further Reading

mongodb-json-schema-to-typescript's People

Contributors

bcherny avatar bradzacher avatar darcyparker avatar adrienjoly avatar joanrieu avatar g-rath avatar speedy37 avatar qm3ster avatar dependabot[bot] avatar gmathieu avatar monolithed avatar ikorolev93 avatar iwan-aucamp-cs avatar jefbarn avatar jochendiekenbrock avatar sokra avatar liooo avatar henkesn avatar simonsiefke avatar ohana54 avatar victorandree avatar devoto13 avatar cherryblossom000 avatar dl748 avatar jrylan avatar skilfullgh avatar thurst0 avatar zhangciwu avatar nicojs avatar qzb avatar

Stargazers

Emily Klassen avatar Carlos Duran avatar Alec Brunelle avatar Francesco Virga avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.