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

no schema with key or ref "http://json-schema.org/draft-04/schema#" #472

Closed
mmc41 opened this issue Apr 27, 2017 · 16 comments
Closed

no schema with key or ref "http://json-schema.org/draft-04/schema#" #472

mmc41 opened this issue Apr 27, 2017 · 16 comments
Labels

Comments

@mmc41
Copy link

mmc41 commented Apr 27, 2017

I have upgraded from ajv 4.x to ajv 5.0 and I now get above errors when validating json files that I generate using the excellent 'typescript-json-schema' module that generate json schema with
"$schema": "http://json-schema.org/draft-04/schema#".

What version of Ajv are you using? Does the issue happen if you use the latest version?
5.0

Ajv options object

allErrors: true, verbose: false, addUsedSchema: false, inlineRefs: false,

JSON Schema

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

Validation result, data AFTER validation, error messages

 Error: no schema with key or ref "http://json-schema.org/draft-04/schema#"

What results did you expect?

The schema to validate like it did in ajv 4.x

Note, as my schemas are autogenerated they are a little difficult to change, so it would be great if Ajv 5 could accept them (like Ajv 4).

@admvx
Copy link

admvx commented Apr 27, 2017

@mmc41 I had this issue too, but found the migration guide under the 5.0.0 release notes: https://github.com/epoberezkin/ajv/releases/tag/5.0.0

@epoberezkin
Copy link
Member

@adamayogo that is correct. @mmc41 this guide explains how to use draft-04 schemas with 5.x.x version. By default it only includes meta-schema for draft-06.

@Domvel
Copy link

Domvel commented Jul 5, 2018

I do not understand why is the property $id with the url to the schema required for the schema? The property $schema is for the schema url, or not?

I fixed the error no schema with key or ref by adding the $id with the url to the json-schema.
Now my files looks like (snippet):

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

I need $schema for the editor (VS Code). Why is id required?

@epoberezkin
Copy link
Member

@Domvel $schema is URI of the meta-schema, $id is recommended rather than required, please see JSON schema spec

@Domvel
Copy link

Domvel commented Jul 6, 2018

@epoberezkin Why is not possible to use ajv without $id? Only with $schema. I just added the id property to work with.

@epoberezkin
Copy link
Member

It is possible to use ajv without $id, it is only needed if you refer to a schema.

@steph643
Copy link

I 'm also experiencing the issue described at the top of this thread. It seems Ajv doesn't accept the $schema field at all. Whatever I put there, I get Error: no schema with key or ref "..."

@epoberezkin
Copy link
Member

@steph643 draft-04 meta-schema has to be added to Ajv instance - please see top of readme.

@steph643
Copy link

@epoberezkin , thanks for your answer.

I use draft-06, not draft-04, but the readme says to call addMetaSchema for draft-06 also. Sorry, I didn't see this, I will give it a try.

Thanks again.

@Yan502
Copy link

Yan502 commented Jul 19, 2022

I have the same problem. Is there a solution

@epoberezkin
Copy link
Member

Ajv v8 no longer supports draft-04, you need to use v6 or migrate your schemas

@Yan502
Copy link

Yan502 commented Jul 19, 2022

image
image

Still don't understand. Can you answer my question? Thank you

ssbarnea added a commit to ssbarnea/ansible-rulebook that referenced this issue Mar 2, 2023
As the support for the very old draft-4 was removed from at least
one critical tool (ajv), we switch to draft-7 which also happens to
be the version used by all the other Ansible related schemas.

Related: ajv-validator/ajv#472
Related: ansible/ansible-lint#3079
Related: ansible#397
ssbarnea added a commit to ssbarnea/ansible-rulebook that referenced this issue Mar 2, 2023
As the support for the very old draft-4 was removed from at least
one critical tool (ajv), we switch to draft-7 which also happens to
be the version used by all the other Ansible related schemas.

Related: ajv-validator/ajv#472
Related: ansible/ansible-lint#3079
Related: ansible#397

We also include the "examples" extension, which informs ansible-lint
about which glob file patters should use this schema.
ssbarnea added a commit to ssbarnea/ansible-rulebook that referenced this issue Mar 2, 2023
As the support for the very old draft-4 was removed from at least
one critical tool (ajv), we switch to draft-7 which also happens to
be the version used by all the other Ansible related schemas.

Related: ajv-validator/ajv#472
Related: ansible/ansible-lint#3079
Related: ansible#397

We also include the "examples" extension, which informs ansible-lint
about which glob file patters should use this schema.
ttuffin pushed a commit to ansible/ansible-rulebook that referenced this issue Mar 2, 2023
As the support for the very old draft-4 was removed from at least
one critical tool (ajv), we switch to draft-7 which also happens to
be the version used by [all the
other](https://github.com/ansible/ansible-lint/tree/main/src/ansiblelint/schemas)
Ansible related schemas.

Related: ajv-validator/ajv#472
Related: ansible/ansible-lint#3079
Related: #397

Co-authored-by: Alex <aizquier@redhat.com>
@ssbarnea
Copy link

ssbarnea commented Mar 2, 2023

I spotted another unexpected side effect:

Error: no schema with key or ref "https://json-schema.org/draft-07/schema"

So basically if someone dares to use the HTTPS or to remove the "#" from the url, ajv stops recognizing the schema, even if from the HTTP point of view the schema file is perfectly accessible.

Not only this, but that means that AJV users are forced to use the unsecure HTTP protocol for loading the schemas, which opens another can of worms.

So far I am inclined to believe that the only way to make it work in all cases is use exactly http://json-schema.org/draft-07/schema# which happens to be its own exposed $id.

@BinToss
Copy link

BinToss commented Aug 27, 2023

Ajv v8 no longer supports draft-04, you need to use v6 or migrate your schemas

from https://ajv.js.org/json-schema.html#draft-04

You can use JSON Schema draft-04 schemas with Ajv from v8.5.0 and the additional package ajv-draft-04 (both ajv and ajv-draft-04 should be installed).

@Bluscream
Copy link

What am i supposed to do if i get this:


Run walbo/validate-json@v1.1.0
Validating JSON files
Finding files from manifest.json

Error: no schema with key or ref "http://json-schema.org/draft-06/schema#"
{
  "$id": "http://json-schema.org/draft-06/schema#",
  "$schema": "http://json-schema.org/draft-06/schema#",
  ...

@nickdnk
Copy link

nickdnk commented Oct 21, 2024

Does anyone know how to both specify $schema and have ajv work correctly on the CLI? This seems like such a weird bug or oversight.

I'm doing:

{
    "$schema": "http://json-schema.org/draft/2019-09/schema#",
    "title": "my schema",
    "description": "foo",
    "type": "object"
}

which works fine for the IDE, but ajv gives me the same error as this issue:

error: no schema with key or ref "http://json-schema.org/draft/2019-09/schema#"

when using:

ajv validate --all-errors -s my_schema.json --spec=draft2019 -d my_data.yml

This is on version 8.17.1.

Edit: I figured it out. Apparently, now the requirements have been inverted since these issues were posted years back. HTTPS is now required for the schema property, or it doesn't work on the CLI, e.g.:

Good:

https://json-schema.org/draft/2019-09/schema

Bad:

http://json-schema.org/draft/2019-09/schema

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

10 participants