@@ -33,6 +33,8 @@ func Properties(libraryPath *paths.Path) (*properties.Map, error) {
33
33
return libraryProperties , nil
34
34
}
35
35
36
+ var schemaObject = make (map [compliancelevel.Type ]* jsonschema.Schema )
37
+
36
38
// Validate validates library.properties data against the JSON schema and returns a map of the result for each compliance level.
37
39
func Validate (libraryProperties * properties.Map , schemasPath * paths.Path ) map [compliancelevel.Type ]* jsonschema.ValidationError {
38
40
referencedSchemaFilenames := []string {
@@ -42,14 +44,15 @@ func Validate(libraryProperties *properties.Map, schemasPath *paths.Path) map[co
42
44
43
45
var validationResults = make (map [compliancelevel.Type ]* jsonschema.ValidationError )
44
46
45
- schemaObject := schema . Compile ( "arduino-library-properties-permissive-schema.json" , referencedSchemaFilenames , schemasPath )
46
- validationResults [compliancelevel .Permissive ] = schema .Validate ( libraryProperties , schemaObject , schemasPath )
47
-
48
- schemaObject = schema .Compile ("arduino-library-properties-schema.json" , referencedSchemaFilenames , schemasPath )
49
- validationResults [ compliancelevel . Specification ] = schema . Validate ( libraryProperties , schemaObject , schemasPath )
47
+ if schemaObject [ compliancelevel . Permissive ] == nil { // Only compile the schemas once.
48
+ schemaObject [compliancelevel .Permissive ] = schema .Compile ( "arduino-library-properties-permissive-schema.json" , referencedSchemaFilenames , schemasPath )
49
+ schemaObject [ compliancelevel . Specification ] = schema . Compile ( "arduino-library-properties-schema.json" , referencedSchemaFilenames , schemasPath )
50
+ schemaObject [ compliancelevel . Strict ] = schema .Compile ("arduino-library-properties-strict -schema.json" , referencedSchemaFilenames , schemasPath )
51
+ }
50
52
51
- schemaObject = schema .Compile ("arduino-library-properties-strict-schema.json" , referencedSchemaFilenames , schemasPath )
52
- validationResults [compliancelevel .Strict ] = schema .Validate (libraryProperties , schemaObject , schemasPath )
53
+ validationResults [compliancelevel .Permissive ] = schema .Validate (libraryProperties , schemaObject [compliancelevel .Permissive ], schemasPath )
54
+ validationResults [compliancelevel .Specification ] = schema .Validate (libraryProperties , schemaObject [compliancelevel .Specification ], schemasPath )
55
+ validationResults [compliancelevel .Strict ] = schema .Validate (libraryProperties , schemaObject [compliancelevel .Strict ], schemasPath )
53
56
54
57
return validationResults
55
58
}
0 commit comments