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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/ex_json_schema/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ defmodule ExJsonSchema.Schema do
end)
end

defp meta04?(%{"$schema" => @draft4_schema_url <> _}), do: true
defp meta04?(%{"$id" => @draft4_schema_url <> _}), do: true
defp meta04?(_), do: false

defp meta06?(%{"$schema" => @draft6_schema_url <> _}), do: true
defp meta06?(%{"$id" => @draft6_schema_url <> _}), do: true
defp meta06?(_), do: false

defp meta07?(%{"$schema" => @draft7_schema_url <> _}), do: true
defp meta07?(%{"$id" => @draft7_schema_url <> _}), do: true
defp meta07?(_), do: false

defp do_get_fragment(nil, _, _ref), do: {:error, :invalid_reference}
Expand Down
9 changes: 9 additions & 0 deletions test/ex_json_schema/schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,18 @@ defmodule ExJsonSchema.SchemaTest do
test "schema is validated against its meta-schema" do
schema = %{"properties" => "foo"}

schema_meta_draft7 = %{
"$schema" => "http://json-schema.org/draft-07/schema#",
"properties" => "foo"
}

assert_raise ExJsonSchema.Schema.InvalidSchemaError,
~s(schema did not pass validation against its meta-schema: [%ExJsonSchema.Validator.Error{error: %ExJsonSchema.Validator.Error.Type{actual: "string", expected: ["object"]}, path: "#/properties"}]),
fn -> resolve(schema) end

assert_raise ExJsonSchema.Schema.InvalidSchemaError,
~s(schema did not pass validation against its meta-schema: [%ExJsonSchema.Validator.Error{error: %ExJsonSchema.Validator.Error.Type{actual: "string", expected: ["object"]}, path: "#/properties"}]),
fn -> resolve(schema_meta_draft7) end
end

test "resolving an absolute reference in a scoped schema" do
Expand Down