0.1.0 • Published 7 years ago
json-schema-prop-types v0.1.0
JSON Schema Prop Types
JSON Schema compatibility layer for React Prop-Types.
Install
npm install json-schema-prop-types
Getting started
// TODO: Code examples
Advanced Usage
TODO: Call off to Ajv docs for advanced Schemas.
Parity with React Prop Types
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" |
Usage in production
It is recommended that you disable prop-types in production as described here: https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types
Dependencies
The Ajv JSON Schema validator powers the validation checks. This is extended by ajv-keywords in order to support validation of functions and classes.
Peer Dependencies
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
0.1.0
7 years ago