Skip to content

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.
@heydtn heydtn force-pushed the heydtn/fix-resolution-bug branch from bf460c7 to cbfef4f Compare November 17, 2021 19:32
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