voxpupuli / json-schema

Ruby JSON Schema Validator
MIT License
1.52k stars 241 forks source link

"Schema not found" error after updating to gem version 2.8.1 #424

Open JaniJegoroff opened 5 years ago

JaniJegoroff commented 5 years ago

I'm writing API tests with RSpec and I do schema validation as part of the tests. Everything is working fine with json-schema gem version 2.8.0.

After updating json-schema gem to version 2.8.1 I get an error

JSON::Schema::SchemaError:
        Schema not found: http://json-schema.org/draft-06/schema#

Example schema I use

{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-06/schema#",
  "$id": "http://example.com/root.json",
  "type": "array",
  "items": {
    "$id": "#/items",
    "type": "object",
    "required": [
      "id",
      "name"
    ],
    "properties": {
      "id": {
        "$id": "#/items/properties/id",
        "type": "integer"
      },
      "name": {
        "$id": "#/items/properties/name",
        "type": "string",
        "pattern": "^(.*)$"
      }
    }
  }
}
iainbeeston commented 5 years ago

I'm afraid that the gem only supports draft 5 and below. Previously the gem would accept draft 6 but it's behaviour was undefined

koenrh commented 5 years ago

That's because the 'draft 6' schema in this gem is currently identified as:

http://json-schema.org/draft/schema# (without the -06 suffix)

https://github.com/ruby-json-schema/json-schema/blob/9f19eb2d9787ecff7f1bbdda84ba74c9da0c2370/lib/json-schema/validators/draft6.rb#L47

Context: https://github.com/ruby-json-schema/json-schema/pull/376

JaniJegoroff commented 5 years ago

Ok, but with -06 suffix I can access from browser and download the schema: http://json-schema.org/draft-06/schema#

Whereas with http://json-schema.org/draft/schema# --> 404

iainbeeston commented 5 years ago

At one point that was correct, but they kept changing the url. Regardless, the gem doesn't support draft 6 syntax, and I'd recommend using draft 5 until we have a chance to fix that

nruth commented 4 years ago

Sorry to post on a 2 year old thread, but just hit this now & wondering if anything has changed, and whether "draft" refers to the json-api spec or the schema trying to describe it, since the spec has been v1 for a while?

nruth commented 4 years ago

To answer my own question (sorry for the noise!) it looks like "draft" refers to the json-schema version, and this gem is unmaintained / incompatible with the version the jsonapi schema is written in, so better to try with https://github.com/davishmcclurg/json_schemer and adapt the rspec matcher in that post to the other gem.

I ended up here while following a Thoughtbot blog post + googling for a pre-existing json-api schema.

tomdaly commented 1 year ago

hi, bumping this issue as I have encountered the same issue in v3.0.0

the README now states that v3.0.0 supports Draft 6, but it does not support it via the $schema property or URI function if the correct URI for draft 6 is used (as found on the json-schema.org specification links page):

https://json-schema.org/draft-06/schema

but does work if the $schema URI is specified as:

http://json-schema.org/draft/schema#

it seems that the URI for the meta-schema at this line needs to be updated to be able to correctly use draft v6: https://github.com/voxpupuli/json-schema/blob/master/lib/json-schema/validators/draft6.rb#L47