@@ -11,6 +11,11 @@ import (
1111
1212// ConfigureCompiler configures a JSON Schema compiler with the desired behavior.
1313func ConfigureCompiler (c * jsonschema.Compiler , o * config.ValidationOptions ) {
14+ // Sanity
15+ if o == nil {
16+ return
17+ }
18+
1419 // nil is the default so this is OK.
1520 c .UseRegexpEngine (o .RegexEngine )
1621
@@ -38,18 +43,32 @@ func NewCompilerWithOptions(o *config.ValidationOptions) *jsonschema.Compiler {
3843}
3944
4045// NewCompiledSchema establishes a programmatic representation of a JSON Schema document that is used for validation.
41- func NewCompiledSchema (name string , jsonSchema []byte , o * config.ValidationOptions ) * jsonschema.Schema {
46+ func NewCompiledSchema (name string , jsonSchema []byte , o * config.ValidationOptions ) (* jsonschema.Schema , error ) {
47+ // Fake-Up a resource name for the schema
48+ resourceName := fmt .Sprintf ("%s.json" , name )
49+
4250 // Establish a compiler with the desired configuration
4351 compiler := NewCompilerWithOptions (o )
4452 compiler .UseLoader (NewCompilerLoader ())
4553
4654 // Decode the JSON Schema into a JSON blob.
47- decodedSchema , _ := jsonschema .UnmarshalJSON (bytes .NewReader (jsonSchema ))
48- _ = compiler .AddResource (fmt .Sprintf ("%s.json" , name ), decodedSchema )
55+ decodedSchema , err := jsonschema .UnmarshalJSON (bytes .NewReader (jsonSchema ))
56+ if err != nil {
57+ return nil , fmt .Errorf ("failed to unmarshal JSON schema: %w" , err )
58+ }
59+
60+ // Give our schema to the compiler.
61+ err = compiler .AddResource (resourceName , decodedSchema )
62+ if err != nil {
63+ return nil , fmt .Errorf ("failed to add resource to schema compiler: %w" , err )
64+ }
4965
5066 // Try to compile it.
51- jsch , _ := compiler .Compile (fmt .Sprintf ("%s.json" , name ))
67+ jsch , err := compiler .Compile (resourceName )
68+ if err != nil {
69+ return nil , fmt .Errorf ("failed to compile JSON schema: %w" , err )
70+ }
5271
5372 // Done.
54- return jsch
73+ return jsch , nil
5574}
0 commit comments