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

Specifying a meta schema in $schema forces validation error: no schema with key or ref "http://json-schema.org/draft-06/schema#" #1274

Closed
3 tasks done
sbusch opened this issue May 3, 2019 · 6 comments
Labels
possibly close To confirm if this issue can be closed

Comments

@sbusch
Copy link
Contributor

sbusch commented May 3, 2019

Prerequisites

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

Example on RJSF playground

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.

@sbusch
Copy link
Contributor Author

sbusch commented May 3, 2019

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#",
  // ...
}

Example on RJSF playground

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 $idkey is seemingly ignored and the error resurfaces again:

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "$id": "UNKNOWN META SCHEMA",
  // ...
}

Example on RJSF playground

@sbusch
Copy link
Contributor Author

sbusch commented May 3, 2019

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 :-)

@epicfaace
Copy link
Member

@sbusch I didn't realize #1130 was a breaking change -- what part of it would you say makes it a breaking change?

@laspluviosillas
Copy link

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

@epicfaace
Copy link
Member

@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

@khateeb82
Copy link

AJV 6.7.0
how to solve this issue?

@jacqueswho jacqueswho added the possibly close To confirm if this issue can be closed label Feb 24, 2022
@stale stale bot closed this as completed Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possibly close To confirm if this issue can be closed
Projects
None yet
Development

No branches or pull requests

5 participants