Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support latest draft version #37

Open
odow opened this issue Sep 5, 2021 · 7 comments
Open

Support latest draft version #37

odow opened this issue Sep 5, 2021 · 7 comments

Comments

@odow
Copy link
Collaborator

odow commented Sep 5, 2021

We currently implement draft-6, but things have moved on since. We should make updates as necessary.

@jmigual
Copy link

jmigual commented May 9, 2023

How is this going? According to the JSON schema people the 2023 draft is not far from being released and it will probably be the first release version.

@odow
Copy link
Collaborator Author

odow commented May 9, 2023

How is this going?

No progress.

I think the blocker was a new release of the test suite: https://github.com/json-schema-org/JSON-Schema-Test-Suite

The last tag was 2.0.0: https://github.com/json-schema-org/JSON-Schema-Test-Suite/releases/tag/2.0.0

I guess we could try getting from main: https://github.com/json-schema-org/JSON-Schema-Test-Suite/tree/main/tests/draft2020-12

@jmigual
Copy link

jmigual commented May 11, 2023

It seems to be officially released in Zenodo under the DOI: 10.5281/zenodo.6973515 (https://zenodo.org/record/6973515). In the meanwhile I opened an issue there (json-schema-org/JSON-Schema-Test-Suite#672)

@jmigual
Copy link

jmigual commented May 12, 2023

They made a new release (https://github.com/json-schema-org/JSON-Schema-Test-Suite/releases) and according to the linked issue (json-schema-org/JSON-Schema-Test-Suite#672) master should be always stable and usable by everyone.

@odow
Copy link
Collaborator Author

odow commented May 13, 2023

Thanks for following up with them. I have no plans to work on this, but I can review a PR if you're interested.

The test suite gets downloaded

const TEST_SUITE_URL = "https://github.com/json-schema-org/JSON-Schema-Test-Suite/archive/2.0.0.zip"

all of the checks are in
https://github.com/fredo-dedup/JSONSchema.jl/blob/master/src/validation.jl

I assume it's a matter of hooking up the new tests, seeing what fails, and then poking away at updating the _validate methods to add support for the new syntax etc.

@odow
Copy link
Collaborator Author

odow commented Aug 23, 2024

I addressed some but not all of this in #57

@odow
Copy link
Collaborator Author

odow commented Aug 23, 2024

I fixed a bunch of things in #57 and #59, but there are still a couple of issues:

if file == "unknownKeyword.json"
# This is an optional test, and to be honest, it is pretty minor. It
# relates to how we handle $id if the user includes part of a schema
# that we don't know how to parse. As a low priority action item, we
# could come back to this.
continue
end

# TODO(odow): fix this failing test
fails =
["retrieved nested refs resolve relative to their URI not \$id"]
if file == "refRemote.json" && tests["description"] in fails
continue
end

I've just been playing whack-a-mole with the $id stuff without a first principles understanding of the basic rules. The code in schema.jl might need a much larger refactor, because fixing one test seems to break another. But that's more time than I currently have available to spend on this.

Here's a simpler script to get started if someone is interested in debugging the outstanding case(s):

using Test
using HTTP
import JSON
using JSONSchema
import Downloads
import ZipFile
const TEST_SUITE_URL = "https://github.com/json-schema-org/JSON-Schema-Test-Suite/archive/23.1.0.zip"
const SCHEMA_TEST_DIR = let
    dest_dir = mktempdir()
    dest_file = joinpath(dest_dir, "test-suite.zip")
    Downloads.download(TEST_SUITE_URL, dest_file)
    for f in ZipFile.Reader(dest_file).files
        filename = joinpath(dest_dir, "test-suite", f.name)
        if endswith(filename, "/")
            mkpath(filename)
        else
            write(filename, read(f, String))
        end
    end
    joinpath(dest_dir, "test-suite", "JSON-Schema-Test-Suite-23.1.0", "tests")
end
GLOBAL_TEST_DIR = Ref{String}("")
server = HTTP.Sockets.listen(HTTP.ip"127.0.0.1", 1234)
HTTP.serve!("127.0.0.1", 1234; server = server) do req
    # Make sure to strip first character (`/`) from the target, otherwise it
    # will infer as a file in the root directory.
    file = joinpath(GLOBAL_TEST_DIR[], "../../remotes", req.target[2:end])
    return HTTP.Response(200, read(file, String))
end
GLOBAL_TEST_DIR[] = joinpath(SCHEMA_TEST_DIR, "draft7")
schema = JSON.parse(raw"""{
    "$id": "http://localhost:1234/some-id",
    "properties": {
        "name": {"$ref": "nested/foo-ref-string.json"}
    }
}""")
id_map = JSONSchema.build_id_map(schema)
JSONSchema.resolve_refs!(schema, JSONSchema.URIs.URI(), id_map, abspath("."))
JSONSchema.validate(Dict("foo" => "a"), JSONSchema.Schema(schema)) === nothing
JSONSchema.validate(Dict("foo" => 1), JSONSchema.Schema(schema)) !== nothing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants