json-schema-to-typings
v1.0.0
Published
A simple way to convert json-schema to typescript typings
Downloads
4
Readme
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
- [x]
id
required for Identifier, will transform to the UpperCameCase - [x]
$ref
only support#/defintions/<id>
andid
same as above
Primitive types
- [x]
type=string
ormaxLength
orminLength
=>string
- [x]
type=boolean
=>string
- [x]
type=number
ortype=integer
ormaximum
|minimum
=>number
- [x]
type=null
=>null
- [x] others =>
any
Interface
- [x]
type=object
orproperties
of^*Properties
- [x]
patternProperties
oradditionalProperties
=>[key: string | number]: ${any or json schema declaration}
Array Type
- [x]
type=array
oritems
or^*Items
=> single typestring[]
and multiple typeArray<string | number>
- [x]
additionalItems
append typeany
or the json schema declaration
Tuple Type
- [x]
items
as an array of schema andadditionalItems=false
Union Type
- [x]
anyOf
- [x]
enum
union with the values and ignore other schema props - [x]
type
as an array
Intersection Type
- [x]
allOf
Ignores:
dependencies
divisibleBy
multipleOf
maxLength
minLength
maximum
maximum
minimum
maxItems
minItems
maxProperties
minProperties
not
/disallow
oneOf
("xor", useanyOf
instead)pattern
patternProperties
uniqueItems