@@ -26,8 +26,7 @@ defmodule ExJsonSchema.Schema do
2626 alias ExJsonSchema.Validator
2727 alias ExJsonSchema.Schema.Ref
2828
29- @ type ref_path :: [ :root | String . t ( ) ]
30- @ type resolved :: ExJsonSchema . data ( ) | % { String . t ( ) => ( Root . t ( ) -> { Root . t ( ) , resolved } ) | ref_path } | true | false
29+ @ type resolved :: ExJsonSchema . data ( )
3130 @ type invalid_reference_error :: { :error , :invalid_reference }
3231
3332 @ current_draft_schema_url "http://json-schema.org/schema"
@@ -60,7 +59,7 @@ defmodule ExJsonSchema.Schema do
6059 resolve ( % Root { schema: schema } , options )
6160 end
6261
63- @ spec get_fragment ( Root . t ( ) , ref_path | ExJsonSchema . json_path ( ) ) ::
62+ @ spec get_fragment ( Root . t ( ) , Ref . t ( ) | ExJsonSchema . json_path ( ) ) ::
6463 { :ok , resolved } | invalid_reference_error | no_return
6564 def get_fragment ( root = % Root { } , ref ) when is_binary ( ref ) do
6665 get_fragment ( root , Ref . from_string ( ref , root ) )
@@ -77,15 +76,15 @@ defmodule ExJsonSchema.Schema do
7776 end
7877 end
7978
80- @ spec get_fragment! ( Root . t ( ) , ref_path | ExJsonSchema . json_path ( ) ) :: resolved | no_return
79+ @ spec get_fragment! ( Root . t ( ) , Ref . t ( ) | ExJsonSchema . json_path ( ) ) :: resolved | no_return
8180 def get_fragment! ( root , ref ) do
8281 case get_fragment ( root , ref ) do
8382 { :ok , schema } -> schema
8483 { :error , :invalid_reference } -> raise_invalid_reference_error ( ref )
8584 end
8685 end
8786
88- @ spec get_ref_schema ( Root . t ( ) , [ :root | String . t ( ) ] ) :: ExJsonSchema . data ( ) | no_return
87+ @ spec get_ref_schema ( Root . t ( ) , Ref . t ( ) ) :: ExJsonSchema . data ( ) | no_return
8988 def get_ref_schema ( % Root { schema: schema } , % Ref { location: :root , fragment: fragment } = ref ) do
9089 case get_ref_schema_with_schema ( schema , fragment , ref ) do
9190 { :error , error } ->
@@ -107,7 +106,7 @@ defmodule ExJsonSchema.Schema do
107106 end
108107
109108 @ spec resolve_root ( boolean | Root . t ( ) ) :: Root . t ( ) | no_return
110- defp resolve_root ( % Root { schema: root_schema } = root ) do
109+ defp resolve_root ( % Root { schema: root_schema } = root , scope \\ "" ) do
111110 schema_version =
112111 root_schema
113112 |> Map . get ( "$schema" , @ current_draft_schema_url <> "#" )
@@ -123,7 +122,7 @@ defmodule ExJsonSchema.Schema do
123122 end
124123
125124 root = % Root { root | version: schema_version }
126- { root , schema } = resolve_with_root ( root , root_schema )
125+ { root , schema } = resolve_with_root ( root , root_schema , scope )
127126
128127 % Root { root | schema: schema }
129128 |> resolve_refs ( schema )
@@ -186,8 +185,6 @@ defmodule ExJsonSchema.Schema do
186185 end
187186 end
188187
189- defp resolve_with_root ( root , schema , scope \\ "" )
190-
191188 defp resolve_with_root ( root , % { "$ref" => ref } , scope ) when is_binary ( ref ) do
192189 do_resolve ( root , % { "$ref" => ref } , scope )
193190 end
@@ -206,7 +203,7 @@ defmodule ExJsonSchema.Schema do
206203 defp resolve_with_id ( root , schema , scope , id ) do
207204 scope =
208205 case URI . parse ( scope ) do
209- % URI { host: nil } - > id
206+ % URI { host: nil } = uri -> to_string ( % URI { uri | fragment: nil } ) < > id
210207 uri -> uri |> URI . merge ( id ) |> to_string ( )
211208 end
212209
@@ -268,7 +265,7 @@ defmodule ExJsonSchema.Schema do
268265
269266 defp resolve_remote_schema ( root , url , remote_schema ) do
270267 root = root_with_ref ( root , url , remote_schema )
271- % Root { schema: schema , refs: refs } = resolve_root ( % Root { root | schema: remote_schema , location: url } )
268+ % Root { schema: schema , refs: refs } = resolve_root ( % Root { root | schema: remote_schema , location: url } , url )
272269
273270 % Root { root | refs: refs }
274271 |> root_with_ref ( url , schema )
0 commit comments