1.0.0 • Published 7 years ago
json-schema-to-typings v1.0.0
JSONSchemaToTypings
A simple way to convert json-schema to typescript typings
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>
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 propstype
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