Coder Social home page Coder Social logo

sfast / types-as-schema Goto Github PK

View Code? Open in Web Editor NEW

This project forked from plantain-00/types-as-schema

0.0 2.0 0.0 11.43 MB

Genetate json scheme, protobuf file, graphQL schema and reasonml/ocaml/rust types from typescript types.

Home Page: https://plantain-00.github.io/types-as-schema/online/

License: MIT License

JavaScript 4.36% HTML 1.62% CSS 1.48% TypeScript 92.53%

types-as-schema's Introduction

types-as-schema

Dependency Status devDependency Status Build Status: Linux Build Status: Windows npm version Downloads type-coverage

Genetate json scheme, protobuf file, graphQL/mongoose(alpha) schema, reasonml(alpha)/ocaml(alpha)/rust(alpha) types and swagger doc from typescript types.

supported types features

  • type literal
  • interface
  • type union
  • interface extends
  • type intersection
  • type array
  • tagged field
  • marked as more precise type
  • enum
  • class
  • class extends
  • muitiple files
  • function / method

unsupported types features

  • variable statement

install

yarn global add types-as-schema

usage

types-as-schema demo/types.ts --json demo/ --protobuf demo/types.proto --graphql demo/types.gql --graphql-root-type demo/root-type.ts --reason demo/types.re --ocaml demo/types.ml --rust demo/types.rs --debug demo/debug.json

parameters description
--json directory for generated json files
--protobuf generated protobuf file
--graphql generated graphql schema file
--graphql-root-type generated graphql root type
--reason generated reason types file
--ocaml generated ocaml types file
--rust generated rust types file
--mongoose generated mongoose schema file
--swagger generated swagger json file
--swagger-base swagger json file that generation based on
--debug generated file with debug information in it
--watch or -w watch mode

protobuf and json schema

  • @type uint32: set type = "uint32"
  • @mapValueType uint32: more detailed type of a map type value

protobuf only

  • @tag 1: tag or id

json schema only

entry:

  • @entry request-protocol.json: the entry file name

common:

  • @title foo: set title = 'foo'
  • @description bar: set description = 'bar'

number:

  • @multipleOf 10: set multipleOf = 10
  • @minimum 70: set minimum = 70
  • @maximum 90: set maximum = 90
  • @exclusiveMinimum 70: set exclusiveMinimum = 70
  • @exclusiveMaximum 90: set exclusiveMaximum = 90
  • @default 10: set default = 10

string:

  • @minLength 10: set minLength = 10
  • @maxLength 20: set maxLength = 20
  • @pattern ^[A-z]{3}$: set pattern = ^[A-z]{3}$
  • @default foo: set default = 'foo'

boolean:

  • @default true: set default = true

object:

  • @minProperties 1: set minProperties = 1
  • @maxProperties 3: set maxProperties = 3
  • @additionalProperties: set additionalProperties = true

array:

  • @uniqueItems: set uniqueItems = true
  • @minItems 1: set minItems = 1
  • @maxItems 10: set maxItems = 10
  • @itemType integer: set item type = "integer"

number[]:

  • @itemMultipleOf 10: set item multipleOf = 10
  • @itemMinimum 70: set item minimum = 70
  • @itemMaximum 90: set item maximum = 90
  • @itemExclusiveMinimum 70: set item exclusiveMinimum = 70
  • @itemExclusiveMaximum 90: set item exclusiveMaximum = 90
  • @itemDefault 10: set item default = 10

string[]:

  • @itemMinLength 10: set item minLength = 10
  • @itemMaxLength 20: set item maxLength = 20
  • @itemPattern ^[A-z]{3}$: set item pattern = ^[A-z]{3}$
  • @itemDefault foo: set item default = 'foo'

boolean[]:

  • @itemDefault true: set item default = true

graphql schema only

  • @param {string} name: set argument name: String!
  • @param {string} [name]: set argument name: String

swagger doc only

  • @method get: set api method
  • @path /pet/{id}: set api url
  • @in query: a parameter in a query, body, header, formData or path
  • @deprecated: set api as deprecated api
  • @tags pet: set api tags, can be seperated by ,

mongoose schema only

  • @index: set index
  • @unique: set unique index
  • @sparse: set sparse index
  • @select: set select
  • @alias index4: set alias

number type alias

type uint32 = number;
type integer = number;

type Foo = {
    bar: uint32;
    foo: integer;
}

types-as-schema's People

Contributors

plantain-00 avatar

Watchers

James Cloos avatar Shushanik Tovmasyan 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.