Skip to content

Commit

Permalink
Use Downloads.jl instead of HTTP.jl for schema downloads (#49)
Browse files Browse the repository at this point in the history
This patch changes the remote schema download to use Downloads.jl
instead of HTTP.jl. Since this was the only usage of HTTP.jl this
dependency is removed.
  • Loading branch information
fredrikekre authored Jul 15, 2023
1 parent 258380c commit b81bc2e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name = "JSONSchema"
uuid = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
version = "1.1.0"
version = "1.2.0"

[deps]
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"

Expand All @@ -17,9 +16,10 @@ ZipFile = "0.8, 0.9, 0.10"
julia = "1.6"

[extras]
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"

[targets]
test = ["Test", "OrderedCollections", "ZipFile"]
test = ["HTTP", "OrderedCollections", "Test", "ZipFile"]
2 changes: 1 addition & 1 deletion src/JSONSchema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

module JSONSchema

import Downloads
import JSON
import HTTP
import URIs

export Schema, validate
Expand Down
15 changes: 11 additions & 4 deletions src/schema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,18 @@ function _recurse_get_element(schema::AbstractVector, element::String)
end

function get_remote_schema(uri::URIs.URI)
r = HTTP.get(uri)
if r.status != 200
error("Unable to get remote schema at $uri. HTTP status = $(r.status)")
io = IOBuffer()
r = Downloads.request(string(uri); output = io, throw = false)
if r isa Downloads.Response && r.status == 200
return Schema(JSON.parse(seekstart(io)))
end
return Schema(JSON.parse(String(r.body)))
msg = "Unable to get remote schema at $uri"
if r isa Downloads.RequestError
msg *= ": " * r.message
elseif r isa Downloads.Response
msg *= ": HTTP status code $(r.status)"
end
return error(msg)
end

function find_ref(
Expand Down

2 comments on commit b81bc2e

@odow
Copy link
Collaborator

@odow odow commented on b81bc2e Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/87595

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.0 -m "<description of version>" b81bc2e4ee2936ddaf83975f4ed78e8edefd4c5a
git push origin v1.2.0

Please sign in to comment.