0.4.1 • Published 6 years ago
@bb-cli/json-schema-to-typedef v0.4.1
Members
Typedefs
jsonSchemaToTypeDefObjs ⇒ Promise.<Array.<TypeDef>>
Convert json schema to js doc typeDef objects.
Kind: global variable
Returns: Promise.<Array.<TypeDef>> - Promise of array of typeDef objects
Param | Type | Description |
---|---|---|
schema | Object | JSON Schema to Convert |
name | String | Top level name for typeDefs |
Example
import { jsonSchemaToTypeDefObjs } from '@bb-cli/json-schema-to-typeDef';
const jsonSchema = {
type: 'array',
items: {
type: 'object',
properties: {
oneProperty: {
type: 'string',
},
twoProperty: {
type: 'object',
properties: {
nestedProperty: {
type: 'number'
}
}
},
},
required: ["twoProperty"]
},
};
console.log(jsonSchemaToTypeDefObjs(jsonSchema, 'myType'));
// Outputs array of 3 typedef objects:
[
{
name: "myType",
type: "Array.<myTypeItem>",
properties: []
},
{
name: "myTypeItem",
type: "Object",
properties: [
{
name: "oneProperty",
isRequired: false,
type: "String",
description: ""
},
{
name: "twoProperty",
isRequired: true,
type: "twoProperty",
description: ""
}
]
},
{
name: "twoProperty",
type: "Object",
properties: [
{
name: "nestedProperty",
isRequired: false,
type: "Number",
description: ""
}
]
}
]
default ⇒ Promise.<Array.<String>>
Convert json schema to js doc typeDef strings
Kind: global variable
Returns: Promise.<Array.<String>> - Promise of Array of typeDef strings
Param | Type | Description |
---|---|---|
schema | Object | JSON Schema to Convert |
name | String | Top level name for typeDefs |
Example
import jsonSchemaToTypeDef from '@bb-cli/json-schema-to-typeDef';
const jsonSchema = {
type: 'array',
items: {
type: 'object',
properties: {
oneProperty: {
type: 'string',
},
twoProperty: {
type: 'object',
properties: {
nestedProperty: {
type: 'number'
}
}
},
},
required: ["twoProperty"]
},
};
console.log(jsonSchemaToTypeDef(jsonSchema, 'myType'));
// Outputs array of 3 typedef strings:
[
"@typedef myType
@type {Array.<myTypeItem>}",
"@typedef myTypeItem
@type {Object}
@property {?String} oneProperty
@property {twoProperty} twoProperty",
"@typedef twoProperty
@type {Object}
@property {?Number} nestedProperty"
];
typeDefToString ⇒ String
Convert a typedef object to a JS Doc string
Kind: global variable
Param | Type |
---|---|
def | TypeDef |
TypeDefProperty : Object
JS Doc Object property
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
name | String | Name of object property |
isRequired | Boolean | Whether property is required for object |
type | String | JS Doc type of property |
description | String | Description of the property |
TypeDef : Object
JS Doc typedef
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
name | String | Name of typedef |
type | String | JS Doc type of typedef |
properties | Array.<TypeDefProperty> | Array of typedef object properties |