Skip to content
Merged
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
7 changes: 7 additions & 0 deletions lib/ex_json_schema/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ defmodule ExJsonSchema.Schema do
end

defp schema_module(schema_url, default \\ Draft7)

defp schema_module("https://json-schema.org/" <> rest, default),
do: schema_module("http://json-schema.org/" <> rest, default)

defp schema_module(@draft4_schema_url <> _, _), do: Draft4
defp schema_module(@draft6_schema_url <> _, _), do: Draft6
defp schema_module(@draft7_schema_url <> _, _), do: Draft7
Expand Down Expand Up @@ -257,6 +261,9 @@ defmodule ExJsonSchema.Schema do
end

@spec remote_schema(String.t()) :: ExJsonSchema.object()
defp remote_schema("https://json-schema.org/" <> rest),
do: remote_schema("http://json-schema.org/" <> rest)

defp remote_schema(@current_draft_schema_url <> _), do: Draft7.schema()
defp remote_schema(@draft4_schema_url <> _), do: Draft4.schema()
defp remote_schema(@draft6_schema_url <> _), do: Draft6.schema()
Expand Down
14 changes: 14 additions & 0 deletions test/ex_json_schema/schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ defmodule ExJsonSchema.SchemaTest do
assert resolve(schema) == %ExJsonSchema.Schema.Root{refs: %{}, schema: schema, version: 7}
end

test "accepts both http:// and https:// forms of the JSON Schema URI" do
http_schema = %{"$schema" => "http://json-schema.org/draft-07/schema#"}
https_schema = %{"$schema" => "https://json-schema.org/draft-07/schema#"}

assert resolve(http_schema).version == 7
assert resolve(https_schema).version == 7

http_draft6 = %{"$schema" => "http://json-schema.org/draft-06/schema#"}
https_draft6 = %{"$schema" => "https://json-schema.org/draft-06/schema#"}

assert resolve(http_draft6).version == 6
assert resolve(https_draft6).version == 6
end

test "schema is validated against its meta-schema" do
schema = %{"properties" => "foo"}

Expand Down
Loading