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

Fix bug when validating schemas that specify an explicit metaschema #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

heydtn
Copy link

@heydtn heydtn commented Nov 17, 2021

Schema.assert_valid_schema/1 was checking whether an input schema was one of the JSON Schema draft metaschemas, and if so, automatically marking it as valid. The problem, though, is that it was checking the $schema field instead of the $id field. This meant that any schema which specified that it's supposed to be checked against a JSON Schema draft would automatically pass even if it wasn't valid.

This can be reproduced with the following

iex(1)> ExJsonSchema.Schema.resolve(%{"properties" => "foo"})
** (ExJsonSchema.Schema.InvalidSchemaError) schema did not pass validation against its meta-schema: [%ExJsonSchema.Validator.Error{error: %ExJsonSchema.Validator.Error.Type{actual: "string", expected: ["object"]}, path: "#/properties"}]
    (ex_json_schema 0.8.1) lib/ex_json_schema/schema.ex:145: ExJsonSchema.Schema.resolve_root/1
iex(1)> ExJsonSchema.Schema.resolve(%{"$schema" => "http://json-schema.org/draft-07/schema#", "properties" => "foo"})
%ExJsonSchema.Schema.Root{
  custom_format_validator: nil,
  definitions: %{},
  location: :root,
  refs: %{},
  schema: %{
    "$schema" => "http://json-schema.org/draft-07/schema#",
    "properties" => "foo"
  },
  version: 7
}

Schema.assert_valid_schema/1 was checking whether an input schema was one of the JSON Schema draft metaschemas, and if so, automatically marking it as valid.  The problem, though, is that it was checking the $schema field instead of the $id field.  This meant that any schema which specified that it's supposed to be checked against a JSON Schema draft would automatically pass even if it wasn't valid.
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

Successfully merging this pull request may close these issues.

1 participant