react-json-schema-proptypes
react-json-schema-proptypes copied to clipboard
Schema.node does not allow a value of 'null'
I could be missing something, but when a component does not have a child, null is passed instead. This means that a component without child will fail the propType validation when Schema.node is used.
For reference, this is the schema that I use.
Test.propTypes = propTypeSchema({
type: 'object',
properties: {
children: {
type: Schema.node,
required: false,
},
route: {
type: 'object',
},
},
});
First of all, it seems I was using Schema.node incorrectly. It should have been children: Schema.node
.
But that still does not fix my problem. In the mean time I am using this to get around it.
Test.propTypes = propTypeSchema({
type: 'object',
properties: {
children: {
oneOf: [{ type: 'null' }, ...Schema.node.oneOf],
},
route: {
type: 'object',
},
},
});
@ddeklerk I think you're using Schema.node
almost correctly, but the definition is missing the null
case. You should be able to do
Test.propTypes = propTypeSchema({
type: 'object',
properties: {
children: Schema.node,
route: {
type: 'object',
},
},
});
Marked as a bug.