JSON Schema compatibility layer for React Prop-Types.
npm install json-schema-prop-types
// TODO: Code examples
TODO: Call off to Ajv docs for advanced Schemas.
This package aims to be at least equal to the props-types package in it's capability. Below is a mapping of prop-types features to this packages solution.
Prop Type | Native Support | Custom Support | Notes |
---|---|---|---|
any | ✅ | JSON Schema blank definition | |
string | ✅ | JSON Schema type "string" | |
number | ✅ | JSON Scehma types "number" or "integer" | |
func | 🚫 | ✅ | Supported by Ajv custom keyword "instanceof" |
bool | ✅ | JSON Schema type "boolean" | |
oneOf | ✅ | JSON Schema keyword "enum" | |
oneOfType | ✅ | JSON Schema keyword "oneOf" | |
array | ✅ | JSON Schema type "array" | |
arrayOf | ✅ | JSON Schema type "array" with keyword "items" | |
object | ✅ | JSON Schema type "object" | |
objectOf | ✅ | JSON Schema keyword "patternProperties" | |
instanceOf | 🚫 | ✅ | Supported by Ajv custom keyword "instanceof" |
shape | ✅ | JSON Schema type "object" with keyword "properties" | |
element | 🚫 | ✅ | Custom definition "_ReactElement" |
node | 🚫 | ✅ | Custom definition "_Node" |
(...).isRequired | ✅ | JSON Schema keyword "required" |
It is recommended that you disable prop-types in production as described here: https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types
The Ajv JSON Schema validator powers the validation checks. This is extended by ajv-keywords in order to support validation of functions and classes.
This package expects to be used with React, React DOM and Prop Types. The following package versions have been tested:
- react - 16.2.0
- react-dom - 16.2.0
- prop-types - 15.6.0