-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage instructions perhaps? #70
Comments
godoc contains examples showing the usage. if your schema file uses other schema files, they are automatically located and compiled. for example consider following schema file {
"properties": {
"p1": {
"type": "boolean"
},
"p2": {
"$ref": "schema2.json"
}
}
} and {
"type": "string"
} then to compile the schema do the following: sch, err := jsonschema.Compile("/example/schema1.json")
if err != nil {
log.Fatalf("%#v", err)
} you can see that you are compiling to validate `/example/sample.json', do the following: data, err := ioutil.ReadFile("/example/sample.json")
if err != nil {
log.Fatal(err)
}
var v interface{}
if err := json.Unmarshal(data, &v); err != nil {
log.Fatal(err)
}
if err = sch.Validate(v); err != nil {
log.Fatalf("%#v", err)
} |
if you want to locate with your own logic, use |
Yeah but I am using |
if the subschema is not in the expected location then say in the above example the compiler looks for schema2, err := ioutil.ReadFile("/somedir/schema2.json")
if err != nil {
log.Fatal(err)
}
compiler.AddResource("file:///example/schema2.json", schema2) |
But reading from file system is sub-optimal and a security issue at runtime (i.e. the user machine can change schemas in-between program restarts). |
this example demonstrates how to load schemas from |
The readme mentions schema introspection, does the package provide a way to generate types/structs/interfaces from the schemas? |
The Schema struct is exported in api. Gererating what you said can be implemented using the information in Schema struct |
The docs are pretty sparse on how to actually use it for validation.
So I create a compiler then what? How do I feed it the other json schemas? How do I validate actual jsons? Can I assert a type of parsed JSON with this? Can I extend
Compiler
struct to have my own$id
/$ref
parsing logic?The text was updated successfully, but these errors were encountered: