react-jsonschema-form
react-jsonschema-form copied to clipboard
Specifying a meta schema in $schema forces validation error: no schema with key or ref "http://json-schema.org/draft-06/schema#"
Prerequisites
- [x] I have read the documentation;
- [x] In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.
- [x] Ideally, I'm providing a sample JSFiddle or a shared playground link demonstrating the issue.
Description
If the schema specifies a meta schema in $schema
:
{
"$schema": "http://json-schema.org/draft-06/schema#",
// ...
}
RJSF then complains with error
no schema with key or ref "http://json-schema.org/draft-06/schema#"
The error is issued by underlying ajv library.
Steps to Reproduce
Validation error is immediately visible.
Expected behavior
Schema can be used without errors.
Actual behavior
See description.
Version
This schema could be used on 1.2.1.
This behaviour (regression?) has been introduced by 1.3.0 and is the same at 1.5.0.
Interestingly, a workaround is to add an $id
referencing the same meta schema:
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://json-schema.org/draft-06/schema#",
// ...
}
So I suppose (without checking the code) that $id
overrides $schema
, and seems to be handled correctly (= not triggering the wrong validation error) in contrast to $schema
.
In case of an invalid meta schema in $id
, the $id
key is seemingly ignored and the error resurfaces again:
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "UNKNOWN META SCHEMA",
// ...
}
Ok, got it, I had to define a 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: ...
Introduced at #1130
@epicfaace some remarks:
-
1.3.0
was a potentially breaking release. Does the project follow semantic versioning? - if the default "draft-07" comes implicitly from ajv, it's better to import and assign it explicitly -> more control over such breaking changes
- http://react-jsonschema-form.readthedocs.io/ is quite outdated, is that known?
- the way the example for defining a custom schema validation is implemented forces a re-rendering of the form each time the parent re-renders (because a new array is constructed every time). The example could stay simple, but this should be at least noted for the copy pasta crowd :-)
@sbusch I didn't realize #1130 was a breaking change -- what part of it would you say makes it a breaking change?
Not sure if this is related, but when trying to make this library work with AJV 6.7.0 (React 16.8.4) importing "Form" from "react-jsonschema-form"; causes Webpack to fail compilation with the following error:
Module build failed (from ./node_modules/babel-loader/lib/index.js): /SyntaxError: /Users/jstrong/webapps/rails/eebos_rails/node_modules/ajv/lib/refs/json-schema-draft-07.json: Unexpected token, expected ";" (2:13) ... @ ./node_modules/ajv/lib/ajv.js 488:19-62 @ ./node_modules/react-jsonschema-form/lib/validate.js
@laspluviosillas sounds like a problem with your webpack config? if you can send me a link to your github repo I can help look into it
AJV 6.7.0 how to solve this issue?