Gojsonshema path to json shema

Hi all
I’m trying to load json schema in project for validate incoming body json with schema
For this i’m using package https://github.com/xeipuuv/gojsonschema
For example i try set path to my schema like this
schemaLoader := gojsonschema.NewReferenceLoader("file://./filename.json")
because json file stored near go file in the same folder
And command
resultValidate, err := gojsonschema.Validate(schemaLoader, loader)
where loader NewGoLoader from instance of struct from request body
err = Reference ./filename.json must be canonical
What i do wrong?

Try an absolute path rather then a relative one, but that’s just a guess.

When i set absolute path then result of validate return err
Maybe more useful another json validator but which one?

func (r *JsonReference) IsCanonical() bool {
return (r.HasFileScheme && r.HasFullFilePath) || (!r.HasFileScheme && r.HasFullUrl)

schemaLoader := gojsonschema.NewReferenceLoader(“file://./filename.json”)

You need absolute path to this json file, somethink like “file://home/blah/blah/filename.json”

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.