Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export ajv for more config options #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';

```

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions src/ajvEx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,4 +24,4 @@ ajv.addKeyword('isFunction', { compile: function() {
return isFunction;
}});

export default ajv;
export default ajv;
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down