Skip to content

Commit 2ff8063

Browse files
authored
Update to URIs.jl (#34)
1 parent 104c984 commit 2ff8063

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

Project.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
name = "JSONSchema"
22
uuid = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
3-
version = "0.3.3"
3+
version = "0.3.4"
44

55
[deps]
66
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
77
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
8-
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
8+
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
99

1010
[compat]
11-
HTTP = "0.8, 0.9"
11+
HTTP = "0.9"
1212
JSON = "0.21"
13+
OrderedCollections = "1"
14+
URIs = "1"
1315
ZipFile = "0.8, 0.9"
1416
julia = "1"
1517

1618
[extras]
17-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1819
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
20+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
21+
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
1922

2023
[targets]
21-
test = ["Test", "OrderedCollections"]
24+
test = ["Test", "OrderedCollections", "ZipFile"]

src/JSONSchema.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module JSONSchema
22

33
using JSON
44
import HTTP
5+
import URIs
56

67
export Schema, validate
78

src/schema.jl

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ function type_to_dict(x)
1414
return Dict(name => getfield(x, name) for name in fieldnames(typeof(x)))
1515
end
1616

17-
function update_id(uri::HTTP.URI, s::String)
18-
id2 = HTTP.URI(s)
17+
function update_id(uri::URIs.URI, s::String)
18+
id2 = URIs.URI(s)
1919
if !isempty(id2.scheme)
2020
return id2
2121
end
@@ -27,7 +27,7 @@ function update_id(uri::HTTP.URI, s::String)
2727
els[:path] =
2828
oldpath == nothing ? id2.path : oldpath.captures[1] * id2.path
2929
end
30-
return HTTP.URI(; els...)
30+
return URIs.URI(; els...)
3131
end
3232

3333
function get_element(schema, path::AbstractString)
@@ -60,7 +60,7 @@ function _recurse_get_element(schema::Vector, element::String)
6060
return schema[index+1]
6161
end
6262

63-
function get_remote_schema(uri::HTTP.URI)
63+
function get_remote_schema(uri::URIs.URI)
6464
r = HTTP.get(uri)
6565
if r.status != 200
6666
error("Unable to get remote schema at $uri. HTTP status = $(r.status)")
@@ -69,7 +69,7 @@ function get_remote_schema(uri::HTTP.URI)
6969
end
7070

7171
function find_ref(
72-
uri::HTTP.URI,
72+
uri::URIs.URI,
7373
id_map::AbstractDict,
7474
path::String,
7575
parent_dir::String,
@@ -82,14 +82,11 @@ function find_ref(
8282
uri = update_id(uri, path)
8383
els = type_to_dict(uri)
8484
delete!.(Ref(els), [:uri, :fragment])
85-
uri2 = HTTP.URI(; els...)
85+
uri2 = URIs.URI(; els...)
8686
is_file_uri = startswith(uri2.scheme, "file") || isempty(uri2.scheme)
8787
if is_file_uri && !isabspath(uri2.path)
8888
# Normalize a file path to an absolute path so creating a key is consistent.
89-
uri2 = HTTP.URIs.merge(
90-
uri2;
91-
path = abspath(joinpath(parent_dir, uri2.path)),
92-
)
89+
uri2 = URIs.URI(uri2; path = abspath(joinpath(parent_dir, uri2.path)))
9390
end
9491
if !haskey(id_map, string(uri2))
9592
# id_map doesn't have this key so, fetch the ref and add it to id_map.
@@ -110,11 +107,11 @@ end
110107

111108
# Recursively find all "$ref" fields and resolve their path.
112109

113-
resolve_refs!(::Any, ::HTTP.URI, ::AbstractDict, ::String) = nothing
110+
resolve_refs!(::Any, ::URIs.URI, ::AbstractDict, ::String) = nothing
114111

115112
function resolve_refs!(
116113
schema::Vector,
117-
uri::HTTP.URI,
114+
uri::URIs.URI,
118115
id_map::AbstractDict,
119116
parent_dir::String,
120117
)
@@ -126,7 +123,7 @@ end
126123

127124
function resolve_refs!(
128125
schema::AbstractDict,
129-
uri::HTTP.URI,
126+
uri::URIs.URI,
130127
id_map::AbstractDict,
131128
parent_dir::String,
132129
)
@@ -154,21 +151,21 @@ end
154151

155152
function build_id_map(schema::AbstractDict)
156153
id_map = Dict{String,Any}("" => schema)
157-
build_id_map!(id_map, schema, HTTP.URI())
154+
build_id_map!(id_map, schema, URIs.URI())
158155
return id_map
159156
end
160157

161-
build_id_map!(::AbstractDict, ::Any, ::HTTP.URI) = nothing
158+
build_id_map!(::AbstractDict, ::Any, ::URIs.URI) = nothing
162159

163-
function build_id_map!(id_map::AbstractDict, schema::Vector, uri::HTTP.URI)
160+
function build_id_map!(id_map::AbstractDict, schema::Vector, uri::URIs.URI)
164161
build_id_map!.(Ref(id_map), schema, Ref(uri))
165162
return
166163
end
167164

168165
function build_id_map!(
169166
id_map::AbstractDict,
170167
schema::AbstractDict,
171-
uri::HTTP.URI,
168+
uri::URIs.URI,
172169
)
173170
if haskey(schema, "id") && schema["id"] isa String
174171
# This block is for draft 4.
@@ -218,7 +215,7 @@ struct Schema
218215
end
219216
schema = deepcopy(schema) # Ensure we don't modify the user's data!
220217
id_map = build_id_map(schema)
221-
resolve_refs!(schema, HTTP.URI(), id_map, parent_dir)
218+
resolve_refs!(schema, URIs.URI(), id_map, parent_dir)
222219
return new(schema)
223220
end
224221
end

0 commit comments

Comments
 (0)