Skip to content

Commit

Permalink
local references using json path were not working as expected. fixes #43
Browse files Browse the repository at this point in the history
  • Loading branch information
andreineculau committed Mar 11, 2017
1 parent ef5bda6 commit 84a6e93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ ErrorType}` where

But most of common cases should work fine.

* internal references (id attribute) are NOT supported

http://json-schema.org/latest/json-schema-core.html#rfc.section.8.2.1

## Contributing

If you see something missing or incorrect, a pull request is most welcome!
Expand Down
24 changes: 16 additions & 8 deletions src/jesse_state.erl
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,29 @@ set_error_list(State, ErrorList) ->
%% @doc Resolve a reference.
-spec resolve_ref(State :: state(), Reference :: binary()) -> state().
resolve_ref(State, Reference) ->
case combine_id(State#state.id, Reference) of
%% Local references
"#" ++ Pointer ->
Id = State#state.id,
CanonicalReference = combine_id(Id, Reference),
[BaseURI | Pointer] = re:split( CanonicalReference
, <<$#>>
, [{return, binary}, unicode]
),
IsLocalReference =
case Id of
undefined ->
BaseURI =:= <<"">>;
_ ->
binary_to_list(BaseURI) =:= Id
end,
case IsLocalReference of
true ->
Path = jesse_json_path:parse(Pointer),
case load_local_schema(State#state.root_schema, Path) of
?not_found ->
jesse_error:handle_schema_invalid(?schema_invalid, State);
Schema ->
set_current_schema(State, Schema)
end;
RemoteURI ->
[BaseURI | Pointer] = re:split( RemoteURI
, <<$#>>
, [{return, binary}, unicode]
),
false ->
case load_schema(State, BaseURI) of
?not_found ->
jesse_error:handle_schema_invalid(?schema_invalid, State);
Expand Down

0 comments on commit 84a6e93

Please sign in to comment.