Closed decentralgabe closed 2 years ago
Note: I see in the readme it says full support of remote references
so perhaps this is a configuration error on my part and this functionality already exists?
Disregard, I figured it out. Sorry 😄
func init() {
jsonschema.Loaders["http"] = httploader.Load
jsonschema.Loaders["https"] = httploader.Load
}
you don't need to explicitly add it to jsonschema.Loaders
. simply do:
import _ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
it automatically adds them to jsonschema.Loaders
. this is already documented in README page.
also would like to mention that httploader
package uses http.DefaultClient
which has no timeouts configured by default.
so you may want to configure timeouts and assign it to httploader.Client
Problem
I'm attempting to validate a piece of JSON against this schema which references a few others schemas.
Code is a bit simplified for an example.
this returns
I am assuming the fix is to add each
$ref
into theLoaders
object.Request
My request is for the library to handle this, attempting to resolve the schema at the URL (perhaps a default HTTP loader). Needing to pre-process each schema for its external URI references before validation can be difficult.
Reference
I am attempting to migrate our open source projects to this library from gojsonschema because it supports the latest drafts. This is a feature that the old library supports: https://github.com/xeipuuv/gojsonschema/blob/master/schemaPool.go#L48