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

Cached schema from file with :list => true fails after second call to validate #440

Open
wasaylor opened this issue Oct 16, 2019 · 0 comments

Comments

@wasaylor
Copy link

Hi,

Experiencing a strange issue with cached schema from file paths. If I have the following block of code:

json = '[{ "foo": "bar" }]'
schema = "schema.json"
options = { :json => true, :list => true }

and the schema.json file contains:

{
  "type": "object",
  "properties": {
    "foo": {
      "type": "string"
    }
  },
  "required": ["foo"]
}

calling JSON::Validator.validate!(schema, json, options) succeeds the first time and JSON::Validator.schemas.keys is:

["file:///redacted/schema.json#"]

calling JSON::Validator.validate!(schema, json, options) a second time raises an error:

JSON::Schema::ValidationError: The property '#/0' of type object did not match the following type: array in schema 7cb19a09-a7b6-55db-9163-2d1595d4f3e4

JSON::Validator.schemas.keys is:

["file:///redacted/schema.json#", "file:///redacted/7cb19a09-a7b6-55db-9163-2d1595d4f3e4#"]

If I look at the two cached schemas in memory schema.json is:

{"type"=>"array", "items"=>{"type"=>"object", "properties"=>{"foo"=>{"type"=>"string"}}, "required"=>["foo"]}}

7cb19a09-a7b6-55db-9163-2d1595d4f3e4 is:

{"type"=>"array", "items"=>{"type"=>"array", "items"=>{"type"=>"object", "properties"=>{"foo"=>{"type"=>"string"}}, "required"=>["foo"]}}}

So it looks like passing :list => true on the second call caches the schema again, making it a list of the already cached list version of the original schema.json file..

For now I'm using :clear_cache => true in the options to prevent this from happening.

(json-schema 2.8.1 on ruby 1.9.3)

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

No branches or pull requests

1 participant