JSONSchemaToTypings
A simple way to convert json-schema to typescript typings
APIs
// convert schema to without external refs; // convert schema to declartions;
Rules
Identifier & References
-
id
required for Identifier, will transform to the UpperCameCase -
$ref
only support#/defintions/<id>
andid
same as above
Primitive types
-
type=string
ormaxLength
orminLength
=>string
-
type=boolean
=>string
-
type=number
ortype=integer
ormaximum
|minimum
=>number
-
type=null
=>null
- others =>
any
Interface
-
type=object
orproperties
of^*Properties
-
patternProperties
oradditionalProperties
=>[key: string | number]: ${any or json schema declaration}
Array Type
-
type=array
oritems
or^*Items
=> single typestring[]
and multiple typeArray<string | number>
-
additionalItems
append typeany
or the json schema declaration
Tuple Type
-
items
as an array of schema andadditionalItems=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", useanyOf
instead)pattern
patternProperties
uniqueItems