react-docgen-to-json-schema
Converts react-docgen output to JSON Schema.

Install
This module requires node >= 6.
npm install --save react-docgen-to-json-schema
Usage
Take this example React component.
import { Component } from 'react'
import PropTypes from 'prop-types'
export default class MyComponent extends Component {
static propTypes = {
foo: PropTypes.number.isRequired,
bar: PropTypes.string,
baz: PropTypes.bool
}
static defaultProps = {
bar: 'bar'
}
render: () => { }
}
react-docgen generates the following JSON:
{
"description": "General component description.",
"displayName": "MyComponent",
"methods": [],
"props": {
"foo": {
"type": {
"name": "number"
},
"required": true,
"description": "Description foo."
},
"bar": {
"type": {
"name": "string"
},
"required": false,
"description": "Description bar.\n\n- markdown list-item 1\n- markdown list-item 2",
"defaultValue": {
"value": "'bar'",
"computed": false
}
},
"baz": {
"type": {
"name": "bool"
},
"required": false,
"description": "Description baz."
}
}
}
react-docgen-to-json-schema takes in this JSON and converts it to the following JSON Schema:
{
"title": "MyComponent",
"type": "object",
"properties": {
"foo": {
"type": "number",
"description": "Description foo."
},
"bar": {
"type": "string",
"description": "Description bar.\n\n- markdown list-item 1\n- markdown list-item 2",
"default": "bar"
},
"baz": {
"type": "boolean",
"description": "Description baz."
}
},
"required": [
"foo"
]
}
API
Converts a single JSON object extracted by react-docgen to JSON Schema.
input object JSON object documenting a single component.
Status
Related
License
MIT © Hydrate