react-json-schema-proptypes icon indicating copy to clipboard operation
react-json-schema-proptypes copied to clipboard

Schema.node does not allow a value of 'null'

Open ddeklerk opened this issue 8 years ago • 2 comments

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',
    },
  },
});

ddeklerk avatar May 06 '16 09:05 ddeklerk

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 avatar May 06 '16 12:05 ddeklerk

@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.

charypar avatar Jun 27 '16 17:06 charypar