1.0.0 • Published 7 years ago

json-schema-to-typings v1.0.0

Weekly downloads
3
License
-
Repository
-
Last release
7 years ago

JSONSchemaToTypings

A simple way to convert json-schema to typescript typings

Build Status NPM Dependencies License

APIs

// convert schema to without external refs
const toSimpleSchema: (schema: JsonSchema, imports: {
    [k: string]: JsonSchema;
}) => JsonSchema;

// convert schema to declartions
const toDeclarations: (schema: JsonSchema) => string;

Rules

Identifier & References

  • id required for Identifier, will transform to the UpperCameCase
  • $ref only support #/defintions/<id> and id same as above

Primitive types

  • type=string or maxLength or minLength => string
  • type=boolean => string
  • type=number or type=integer or maximum | minimum => number
  • type=null => null
  • others => any

Interface

  • type=object or properties of ^*Properties
  • patternProperties or additionalProperties => [key: string | number]: ${any or json schema declaration}

Array Type

  • type=array or items or ^*Items => single type string[] and multiple type Array<string | number>
  • additionalItems append type any or the json schema declaration

Tuple Type

  • items as an array of schema and additionalItems=false

Union Type

  • anyOf
  • enum union with the values and ignore other schema props
  • type as an array

Intersection Type

  • allOf

Ignores:

  • dependencies
  • divisibleBy
  • multipleOf
  • maxLength
  • minLength
  • maximum
  • maximum
  • minimum
  • maxItems
  • minItems
  • maxProperties
  • minProperties
  • not/disallow
  • oneOf ("xor", use anyOf instead)
  • pattern
  • patternProperties
  • uniqueItems
1.0.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago