Closed harryhoch closed 1 year ago
Thanks @harryhoch
There is an issue with previous schema versions with the examples which has been addressed in commit 461b2cb4982209fcae5a3697c61c8a9d1bb01329 in PR #38 (in preparation):
(sorry about that).
Also v0.0.0.9 version was erroneously using the draft-07
json schema version. Using a later schema version (v.0.0.1 and above) works off json schema version 2020-12
which does recognise uri
format.
As for validating files, ideally use the validate_config()
function in hubUtils
.
To test against the latest schema in the under development branch you could use :
validate_config(hub_path ="path-to-hub",
config = "admin",
branch = "br-v1.0.0",
schema_version = "v1.0.0")
Once v1.0.0 is merged I suggest you update the schema_version
property in your config to https://raw.githubusercontent.com/Infectious-Disease-Modeling-Hubs/schemas/main/v1.0.0/admin-schema.json
. Then you can just use:
validate_config(hub_path ="path-to-hub",
config = "admin")
which will use the hub schema version specified in the file by default. See https://infectious-disease-modeling-hubs.github.io/hubUtils/reference/validate_config.html for more details
Interesting. I tried to validate using ajv-cli against the 2020-12 version. Not sure why that didn't work. Suggest that if we want folks to rely on hubUtils we make it clear in the docs that other means of validation might not work...
Hmmm that's really strange! here's the docs for 2020-12 and it lists uri
as a valid format: https://json-schema.org/understanding-json-schema/reference/string.html#resource-identifiers
I feel ajv-cli
with 2020-12 should have worked (it's what the hubUtils function uses under the hood and is a worthy alternative if people prefer it.)
How did you specify the json schema version if you don't mind? Did you overwrite it in the admin-schema.json
file?
Looking at the ajv-cli
docs I'm imagining you used --spec=draft2020
argument. I wonder whether that doesn't override the version specified in "$schema"
property of admin-schema.json
?
Basically, trying to run ajv to validate the admin.json in the simple example against admin-schema.json, with --spec=draft2020 to specify the version.
I get output like the following:
(base) harry@harryh-mdt hub-config % ajv --spec=draft2020 -s ../../schemas/v0.0.1/admin-schema.json -d admin.json schema ../../schemas/v0.0.1/admin-schema.json is invalid error: unknown format "uri" ignored in schema at path "#/properties/schema_version"
it might.
i get a slightly different result without the spec:
ajv -s ../../schemas/v0.0.1/admin-schema.json -d admin.json schema ../../schemas/v0.0.1/admin-schema.json is invalid error: no schema with key or ref "https://json-schema.org/draft/2020-12/schema"
Hmmm very strange. I'll take a look into it as I feel this should work
So looking into this a bit, it seems ajv
does not support https
versions of the schema version urls https://stackoverflow.com/questions/69133771/ajv-no-schema-with-key-or-ref-https-json-schema-org-draft-07-schema 🤔
Tried editing admin-schema.json to use http instead of https and got the following:
(base) harry@harryh-mdt hub-config % ajv --spec=draft2020 -s ../../schemas/v0.0.1/admin-schema.json -d admin.json schema ../../schemas/v0.0.1/admin-schema.json is invalid error: no schema with key or ref "http://json-schema.org/draft/2020-12/schema"
I'm not sure that this is important enough to dig into. Just wanted to make sure it was noted somewhere in case someone tries to use ajv or something similar to validate...
Trying to use ajv-cli to validate against admin-schema.json, there are a few problems.