json-yup
A simple utility for converting a JSON schema into Yup schema.
Setup
npm install -S json-yup
import createValidationSchema from 'json-yup';
API
;
Arguments
Argument | Type | Description |
---|---|---|
schema | Object | A valid JSON schema conforming to JSON schema specifications. |
customValidationFields | Object | Custom Yup mappings for schema properties |
Options
Property | Type | Description |
---|---|---|
blackList | Array | A list of fields to omit from the schema. |
customValidationFields | Object | Custom Yup mappings for schema properties |
validationTypes | Object | Custom Yup mappings for schema types. |
Returns
Yup validation object
Usage
// Valid JSON Schemaconst jsonSchema = "type": "object" "required": "first_name" "properties": "create_at": "type": "string" "first_name": "type": "string" "age": "type": "number" "min": 1 "max": 200 ; // Build Yup Schemaconst validationSchema = ; // Check validityvalidationSchema