Skip to content
Genetate json schema, protobuf file, graphQL schema and reasonml/ocaml/rust types from typescript types.
TypeScript JavaScript HTML CSS
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
bin
demo
online
prerender
screenshots
spec
src
.browserslistrc
.editorconfig
.eslintignore
.eslintrc
.gitignore
.markdownlint.json
.stylelintrc
.travis.yml
CODE_OF_CONDUCT.md
LICENSE
README.md
appveyor.yml
clean-release.config.js
clean-run.config.js
clean-scripts.config.js
commitlint.config.js
package.json
postcss.config.js
tsconfig.base.json
tsconfig.eslint.json
yarn.lock

README.md

types-as-schema

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

Genetate json schema, 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
  • Pick

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
--loose do not force additionalProperties

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;
}
You can’t perform that action at this time.