Closed duccioa closed 2 years ago
I have posted a question regarding the same issue on Stackoverflow, for the moment the answer is that it is not supported by {jsonvalidate}
yes, there's something up with our logic for supporting this. As the docs linked by the SO user indicate, ajv requires that the wrapper library resolves the path references as ajv does not have access to the filesystem, and this is a bit fiddly.
We will resolve this at some point, but I'm afraid it's not at the top of our list at the moment. If you wanted to tackle it yourself, the code to change is in https://github.com/ropensci/jsonvalidate/blob/master/R/read.R and a test case could easily be fashioned from your nice reprex, a PR would be great if you have time
Hi @duccioa, @r-ash has now fixed this in #62, can you give it a try please?
Hello, Thanks for the quick fix. I have created a reprex for my current situation. It works with the new patch, where it would fail with the pre-patch version.
library(jsonvalidate)
parent = c(
'{',
' "type":"object",',
' "required":["child1"],',
' "properties":{',
' "child1":{',
' "$ref":"sub/child1.json"',
' }',
' }',
'}'
)
child1 = c(
'{',
' "type":"object",',
' "properties":{',
' "child2":{',
' "$ref":"sub/child2.json"',
' }',
' }',
'}'
)
child2 = c(
'{',
' "type":"string",',
' "enum":["test"]',
'}'
)
dir = file.path(tempdir(), "jsonvalidate_test")
schemadir = file.path(dir, "schemas")
schemasubdir1 = file.path(schemadir, "sub")
schemasubdir2 = file.path(schemasubdir1, "sub")
dir.create(schemasubdir2, recursive = TRUE, showWarnings = FALSE)
writeLines(parent, file.path(schemadir, "parent.json"))
writeLines(child1, file.path(schemasubdir1, "child1.json"))
writeLines(child2, file.path(schemasubdir2, "child2.json"))
list.files(schemadir, recursive = TRUE)
#> [1] "parent.json" "sub/child1.json" "sub/sub/child2.json"
json_validate('{"child1":{"child2":"test"}}', file.path(schemadir, "parent.json"), engine = "ajv")
#> [1] TRUE
json_validate('{"child1":{"child2":""}}', file.path(schemadir, "parent.json"), engine = "ajv")
#> [1] FALSE
unlink(dir, recursive = TRUE)
Created on 2022-09-21 with reprex v2.0.2
Hello, I am trying to validate a json file with nested references. Let's say a 'user' json file with its 'address' sub-schema. 'address' also has a sub-schema. The sub-schemas are all contained in a 'sub-schema/' folder. The files are organised as following:
and they are referenced
user -> sub-schemas/address -> sub-schemas/city
Here's the reproducible code in R which gives the error:
Created on 2022-08-29 with reprex v2.0.2
I managed to make it work if I put the files all in the same folder:
And I reference as following:
But, as soon as I move the sub-schemas in a sub-folder I can't make it work.
Thank you!