Schema and json rejected; error message: schema must be canonical
MichaelBaySAP opened this issue · 1 comments
MichaelBaySAP commented
schema2.json
{ "$schema": "http://json-schema.org/draft-07/schema", "definitions": { "templateDefinition": { "description": "The overall Template Definition.", "type": "object", "properties": { "kind": "string" } } } }
testinput2.json
{ "templateDefinition": { "kind": "test" } }
Test Code
`schemaLoader := gojsonschema.NewReferenceLoader("file://schema2.json")
documentLoader := gojsonschema.NewReferenceLoader("file://testinput2.json")
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
if err != nil {
panic(err.Error())
}
if result.Valid() {
fmt.Printf("The document is valid\n")
} else {
fmt.Printf("The document is not valid. see errors :\n")
for _, desc := range result.Errors() {
fmt.Printf("- %s\n", desc)
}
}`
jaypipes commented
@MichaelBaySAP use file:///schema2.json
(note: the prefix for files is file://
and then you need an absolute path, which on Linux systems, starts with another forward slash.)