fredo-dedup / JSONSchema.jl

JSON Schema validation package for Julia
Other
31 stars 12 forks source link

Add support for JSON3 #41

Closed acdupont closed 1 year ago

acdupont commented 1 year ago

JSON3 uses AbstractArray, AbstractDict in the implementation of it's parsed json types. To add support for JSON3 JSONSchema, it seems all that needs to be done is to change the corresponding concrete types to abstract types.

The first and only test so far for these changes is the following example:

Schema

{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "type": "array"
}

json

[
]

REPL reproducing behavior

julia> schema_array
JSON3.Object{Base.CodeUnits{UInt8, String}, Vector{UInt64}} with 2 entries:
  Symbol("\$schema") => "https://json-schema.org/draft/2019-09/schema"
  :type              => "array"

julia> json_array
0-element JSON3.Array{Union{}, Base.CodeUnits{UInt8, String}, Vector{UInt64}}

julia> result = JSONSchema.validate(JSONSchema.Schema(schema_array), json_array)
Validation failed:
path:         top-level
instance:     Union{}[]
schema key:   type
schema value: array

REPL on PR branch

julia> JSONSchema.isvalid(JSONSchema.Schema(schema_array), json_array)
true
odow commented 1 year ago

Just some formatting failures that need fixing:

https://github.com/fredo-dedup/JSONSchema.jl/actions/runs/4568925572/jobs/8064573055?pr=41

acdupont commented 1 year ago

Just some formatting failures that need fixing:

https://github.com/fredo-dedup/JSONSchema.jl/actions/runs/4568925572/jobs/8064573055?pr=41

I'm not sure where these errors are coming from, I only changed text such as Vector to AbstractVector and such, I did not change any formatting. Output such as:

-function build_id_map!(id_map::AbstractDict, schema::AbstractVector, uri::URIs.URI)
+function build_id_map!(
+    id_map::AbstractDict,
+    schema::AbstractVector,
+    uri::URIs.URI,
+)

is confusing because the version of function build_id_map! in my codebase is one line. Is this output saying the one line should be replaced with the 5 lines then, rather than saying it was replaced but is a formatting error?

odow commented 1 year ago

I'm not sure where these errors are coming from, I only changed text such as Vector to AbstractVector and such, I did not change any formatting

The formatter enforces a maximum line length:

https://github.com/fredo-dedup/JSONSchema.jl/blob/767032514d817c3ceca2a9db2a63da429f9b9b55/.JuliaFormatter.toml#L6

The new lines are too long. I've fixed in the recent commits.