1.0.0 • Published 9 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
idrequired for Identifier, will transform to the UpperCameCase$refonly support#/defintions/<id>andidsame as above
Primitive types
type=stringormaxLengthorminLength=>stringtype=boolean=>stringtype=numberortype=integerormaximum|minimum=>numbertype=null=>null- others =>
any
Interface
type=objectorpropertiesof^*PropertiespatternPropertiesoradditionalProperties=>[key: string | number]: ${any or json schema declaration}
Array Type
type=arrayoritemsor^*Items=> single typestring[]and multiple typeArray<string | number>additionalItemsappend typeanyor the json schema declaration
Tuple Type
itemsas an array of schema andadditionalItems=false
Union Type
anyOfenumunion with the values and ignore other schema propstypeas an array
Intersection Type
allOf
Ignores:
dependenciesdivisibleBymultipleOfmaxLengthminLengthmaximummaximumminimummaxItemsminItemsmaxPropertiesminPropertiesnot/disallowoneOf("xor", useanyOfinstead)patternpatternPropertiesuniqueItems