xeipuuv / gojsonschema

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

[BUG] Validation not working #345

Open ciolo opened 2 years ago

ciolo commented 2 years ago

Hi, Maybe I got the configuration wrong, but following the examples in the README the validation doesn't work correctly. In detail:

documentLoader := gojsonschema.NewGoLoader(feed)
schemaLoader := gojsonschema.NewGoLoader(v.Schema)
result, err := gojsonschema.Validate(schemaLoader, documentLoader)

feed and v.Schema they could be anything and validation returns no errors. Why? Can you help me plz?

Thanks.

dadav commented 1 year ago

I'm also experiencing something like this. In my case I'm doing it like this:

    sl := gojsonschema.NewSchemaLoader()
    sl.Validate = true

    if err := sl.AddSchemas(gojsonschema.NewStringLoader(string(jsonStr))); err != nil {
        return err
    }

I was expecting that this would return an error if someone would use for example type: foobar in their jsonschema. But nothing happens...no errors.