Skip to content

Commit cb43cc2

Browse files
committed
Add schemas path parameter to schema.Compile()
This allows the schemas path to be specified by the caller.
1 parent a86a8fc commit cb43cc2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

check/checkdata/schema/schema.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,20 @@ import (
1010
"github.com/xeipuuv/gojsonschema"
1111
)
1212

13-
// Compile compiles the schema files specified by the filename arguments and returns the compiled schema.
14-
func Compile(schemaFilename string, referencedSchemaFilenames []string) *gojsonschema.Schema {
13+
var schemasPath *paths.Path
14+
15+
func init() {
1516
workingPath, _ := os.Getwd()
16-
schemasPath := paths.New(workingPath)
17+
schemasPath = paths.New(workingPath)
18+
}
1719

20+
// SchemasPath returns the path to the folder containing the JSON schemas.
21+
func SchemasPath() *paths.Path {
22+
return schemasPath
23+
}
24+
25+
// Compile compiles the schema files specified by the filename arguments and returns the compiled schema.
26+
func Compile(schemaFilename string, referencedSchemaFilenames []string, schemasPath *paths.Path) *gojsonschema.Schema {
1827
schemaLoader := gojsonschema.NewSchemaLoader()
1928

2029
// Load the referenced schemas.

project/library/libraryproperties/libraryproperties.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func Properties(libraryPath *paths.Path) (*properties.Map, error) {
2020
// Validate validates library.properties data against the JSON schema.
2121
func Validate(libraryProperties *properties.Map) *gojsonschema.Result {
2222
referencedSchemaFilenames := []string{}
23-
schemaObject := schema.Compile("arduino-library-properties-schema.json", referencedSchemaFilenames)
23+
schemaObject := schema.Compile("arduino-library-properties-schema.json", referencedSchemaFilenames, schema.SchemasPath())
2424

2525
return schema.Validate(libraryProperties, schemaObject)
2626
}

0 commit comments

Comments
 (0)