From ce2f89d6a900fc1a31e2da3550fdd93cb9438f10 Mon Sep 17 00:00:00 2001 From: Tim de Koning Date: Wed, 19 Apr 2017 17:59:25 +0200 Subject: [PATCH 1/2] export ajv for more config options --- README.md | 4 +++- src/index.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d462cf5..8ce6662 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ _* This will create a new object rather than mutating existing ones so you're sa ## API ``` js -import createPropTypes, {getComponentSchema, Schema, SchemaSymbol} from 'react-json-schema-proptypes'; +import createPropTypes, {getComponentSchema, Schema, SchemaSymbol, ajv} from 'react-json-schema-proptypes'; ``` @@ -120,6 +120,8 @@ Is a schema that validates a React node. (Gives a schema represetation equivale #### Schema.func Is a schema that validates a function. +### ajv +The internally used instance of Ajv(https://github.com/epoberezkin/ajv). This instance may be configured e.g. to support nested schema's (See (https://github.com/epoberezkin/ajv#api)[https://github.com/epoberezkin/ajv#api]) ## Caveats diff --git a/src/index.js b/src/index.js index 9659e0a..944c19a 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,7 @@ import omitDeprecated from './util'; export * as Schema from './schemas'; export fake from './fake'; - +export { ajv }; export const SchemaSymbol = Symbol.for('react-json-schema-proptypes'); function name(component) { From 9b12cadd9b1176d2f2f7991199a730d6c178a1c6 Mon Sep 17 00:00:00 2001 From: Tim de Koning Date: Tue, 18 Jul 2017 16:45:05 +0200 Subject: [PATCH 2/2] Update AJV to prevent webpack bundling issues --- package.json | 2 +- src/ajvEx.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index bf5bf08..aa551ed 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "sinon": "^1.17.3" }, "dependencies": { - "ajv": "^3.8.5", + "ajv": "^5.2.2", "ajv-i18n": "^1.2.0", "faker": "^3.1.0", "json-schema-faker": "^0.3.0", diff --git a/src/ajvEx.js b/src/ajvEx.js index e6103dd..276eff2 100644 --- a/src/ajvEx.js +++ b/src/ajvEx.js @@ -2,7 +2,10 @@ import AJV from 'ajv'; import * as React from 'react'; import isFunction from 'lodash/isFunction'; -const ajv = AJV({errorDataPath: 'property'}); // restore pre v2.0 behavior +const ajv = AJV({ + errorDataPath: 'property', // restore pre v2.0 behavior + unknownFormats: 'ignore' // restore pre v5.0 behavior +}); function safeEscapeQuotes(str) { return str.replace(/\\([\s\S])|(')/g,"\\$1$2").replace(/\\([\s\S])|(")/g,"\\$1$2"); // escape only if not escaped already @@ -21,4 +24,4 @@ ajv.addKeyword('isFunction', { compile: function() { return isFunction; }}); -export default ajv; \ No newline at end of file +export default ajv;