xeipuuv / gojsonschema

An implementation of JSON Schema, draft v4 v6 & v7 - Go language
2.56k stars 358 forks source link

Schema and json rejected; error message: schema must be canonical #342

Open MichaelBaySAP opened 3 years ago

MichaelBaySAP commented 3 years ago

schema2.json { "$schema": "http://json-schema.org/draft-07/schema", "definitions": { "templateDefinition": { "description": "The overall Template Definition.", "type": "object", "properties": { "kind": "string" } } } }

image

testinput2.json { "templateDefinition": { "kind": "test" } } image

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)
    }
}`

image

Error message: image

jaypipes commented 2 years ago

@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.)