Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

types-as-schema

1.29.1 • Public • Published

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
  • 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;
}

Keywords

none

Install

npm i types-as-schema

DownloadsWeekly Downloads

34

Version

1.29.1

License

MIT

Unpacked Size

123 kB

Total Files

17

Last publish

Collaborators

  • avatar