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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
strategy:
fail-fast: false
matrix:
version: ['1.6', '1'] # Test against LTS and current minor release
version: ['1.10', '1'] # Test against LTS and current minor release
os: [ubuntu-latest, macOS-latest, windows-latest]
arch: [x64]
include:
# Also test against 32-bit Linux on LTS.
- version: '1.6'
- version: '1.10'
os: ubuntu-latest
arch: x86
steps:
Expand Down
11 changes: 8 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
name = "JSONSchema"
uuid = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
version = "1.4.1"
version = "1.5.0"

[deps]
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"

[weakdeps]
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"

[extensions]
JSONSchemaJSON3Ext = "JSON3"

[compat]
JSON = "0.21"
JSON3 = "1"
URIs = "1"
julia = "1.6"
julia = "1.9"
38 changes: 38 additions & 0 deletions ext/JSONSchemaJSON3Ext.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) 2018: fredo-dedup and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

module JSONSchemaJSON3Ext

import JSONSchema
import JSON3

_to_base_julia(x) = x

_to_base_julia(x::JSON3.Array) = _to_base_julia.(x)

# This method unintentionally allows JSON3.Object{Symbol,Any} objects as both
# data and the schema because it converts to Dict{String,Any}. Because we don't
# similarly convert Base.Dict, Dict{Symbol,Any} results in errors. This can be
# confusing to users.
#
# We can't make this method more restrictive because that would break backwards
# compatibility. For more details, see:
# https://github.com/fredo-dedup/JSONSchema.jl/issues/62
function _to_base_julia(x::JSON3.Object)
return Dict{String,Any}(string(k) => _to_base_julia(v) for (k, v) in x)
end

function JSONSchema.validate(
schema::JSONSchema.Schema,
x::Union{JSON3.Object,JSON3.Array},
)
return JSONSchema.validate(schema, _to_base_julia(x))
end

function JSONSchema.Schema(schema::JSON3.Object; kwargs...)
return JSONSchema.Schema(_to_base_julia(schema); kwargs...)
end

end
1 change: 0 additions & 1 deletion src/JSONSchema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module JSONSchema

import Downloads
import JSON
import JSON3
import URIs

export Schema, validate
Expand Down
13 changes: 0 additions & 13 deletions src/schema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,6 @@ function build_id_map!(
return
end

# Turning JSON3 read files in to base Julia dicts with string keys
_to_base_julia(x) = x

_to_base_julia(x::JSON3.Array) = _to_base_julia.(x)

function _to_base_julia(x::JSON3.Object)
return Dict{String,Any}(string(k) => _to_base_julia(v) for (k, v) in x)
end

"""
Schema(schema::AbstractDict; parent_dir::String = abspath("."))

Expand Down Expand Up @@ -303,8 +294,4 @@ my_schema = Schema(
"""
Schema(schema::String; kwargs...) = Schema(JSON.parse(schema); kwargs...)

function Schema(schema::JSON3.Object; kwargs...)
return Schema(_to_base_julia(schema); kwargs...)
end

Base.show(io::IO, ::Schema) = print(io, "A JSONSchema")
4 changes: 0 additions & 4 deletions src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ function validate(schema::Schema, x)
return _validate(x, schema.data, "")
end

function validate(schema::Schema, x::Union{JSON3.Object,JSON3.Array})
return validate(schema, _to_base_julia(x))
end

Base.isvalid(schema::Schema, x) = validate(schema, x) === nothing

# Fallbacks for the opposite argument.
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ JSON = "0.21"
JSON3 = "1"
OrderedCollections = "1"
ZipFile = "0.8, 0.9, 0.10"
julia = "1.6"
julia = "1.9"
Loading