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

Add more schemas to validate against #1130

Merged
merged 32 commits into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
248d34c
Add more schemas to validate against
Jan 16, 2019
9a87fe8
Edit validate.js so that it calls addMetaSchema conditionally
Jan 21, 2019
95bec5f
Add props which accepts custom schemas for ajv
Jan 22, 2019
3167d36
remove unnecesary fallback
Jan 23, 2019
48b225f
rename variable name
Jan 23, 2019
8c32f54
add documentation for `metaSchema` prop
Jan 23, 2019
8aff86e
Update docs/validation.md
epicfaace Jan 28, 2019
912d9d8
Update src/validate.js
epicfaace Jan 28, 2019
8fe272f
Update src/validate.js
epicfaace Jan 28, 2019
ea3d723
Update docs/validation.md
epicfaace Jan 28, 2019
09973aa
Update docs/validation.md
epicfaace Jan 28, 2019
573b5f9
Update docs/validation.md
epicfaace Jan 28, 2019
02e2895
return errors from validation in validateFormData
Jan 28, 2019
d159262
add initial tests for meta schemas
Jan 28, 2019
ae70488
add one proper test case
Jan 28, 2019
a3a470e
add more test cases
Jan 28, 2019
fbc20d6
Update docs/validation.md
epicfaace Jan 29, 2019
937ee6f
Add test cases for multiple metaSchemas in validateFormData
Jan 29, 2019
cc119a2
Change prop name and update docs
Jan 31, 2019
4758a1f
Change additionalMetaSchemas prop to array only and remove console.error
Feb 4, 2019
bd247de
make sure that validateFormData's additionalMetaShemas argument is al…
Feb 21, 2019
1348751
Commit "broken" test to see whether they pass
Feb 21, 2019
d7fc731
Fix tests and create new Ajv instance when additionalMetaSchemas changes
Feb 21, 2019
438a762
fix: create new ajv instance when additionalMetaSchemas prop is null,…
epicfaace Feb 23, 2019
01a7758
handle validation errors
Feb 25, 2019
2ec6ecc
fix tests and delete validation errors
Feb 25, 2019
83509dc
Delete unneeded field in return statement
Feb 25, 2019
bbd8bdb
dont stop showing red overlay when validation errors are present
Feb 25, 2019
2c2923e
Make errors and test more sensible
Feb 25, 2019
7469b1a
rename variable
Feb 25, 2019
2e5d5b9
handle only $schema related errors
Feb 26, 2019
2baace1
fix tests
Feb 26, 2019
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
33 changes: 33 additions & 0 deletions docs/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,39 @@ render((
> received as second argument.
> - The `validate()` function is called **after** the JSON schema validation.

### Custom schema validation

To have your schemas validated against any other meta schema than draft-07 (the current version of [JSON Schema](http://json-schema.org/)), make sure your schema has a `$schema` attribute that enables the validator to use the correct meta schema. For example:
epicfaace marked this conversation as resolved.
Show resolved Hide resolved

```json
{
"$schema": "http://json-schema.org/draft-04/schema#",
...
}
```

Note that react-jsonschema-form only supports the latest version of JSON Schema, draft-07, by default. To support additional meta schemas pass them through the `additionalMetaSchemas` prop to your `Form` component:
epicfaace marked this conversation as resolved.
Show resolved Hide resolved

```jsx
const additionalMetaSchemas = require("ajv/lib/refs/json-schema-draft-04.json");

render((
<Form schema={schema}
additionalMetaSchemas={[additionalMetaSchemas]}/>
), document.getElementById("app"));
```

In this example `schema` passed as props to `Form` component can be validated against draft-07 (default) and by draft-04 (added), depending on the value of `$schema` attribute.

`additionalMetaSchemas` also accepts more than one meta schema:

```jsx
render((
<Form schema={schema}
additionalMetaSchemas={[metaSchema1, metaSchema2]} />
), document.getElementById("app"));
```

### Custom error messages

Validation error messages are provided by the JSON Schema validation by default. If you need to change these messages or make any other modifications to the errors from the JSON Schema validation, you can define a transform function that receives the list of JSON Schema errors and returns a new list.
Expand Down
Loading