Skip to content

Commit 7279881

Browse files
committed
Move JSON schema compiler creation into validateSchema function
- Better encapsulation: compiler is only used within validateSchema - Cleaner separation of concerns - Each validation gets its own fresh compiler instance - Simplifies the runValidation function
1 parent 3042bf7 commit 7279881

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

tools/validate-schemas/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,12 @@ func runValidation() error {
3636
}
3737

3838
expectedSchemaCount := len(schemas)
39-
compiler := jsonschema.NewCompiler()
40-
compiler.Draft = jsonschema.Draft7
41-
4239
validatedCount := 0
4340

4441
for _, schemaFile := range schemas {
4542
log.Printf("Validating %s...", schemaFile.name)
4643

47-
if err := validateSchema(compiler, schemaFile.path); err != nil {
44+
if err := validateSchema(schemaFile.path); err != nil {
4845
log.Printf(" ❌ Invalid: %v", err)
4946
} else {
5047
log.Printf(" ✅ Valid JSON Schema")
@@ -61,7 +58,7 @@ func runValidation() error {
6158
return nil
6259
}
6360

64-
func validateSchema(compiler *jsonschema.Compiler, path string) error {
61+
func validateSchema(path string) error {
6562
data, err := os.ReadFile(path)
6663
if err != nil {
6764
return fmt.Errorf("failed to read file: %w", err)
@@ -72,6 +69,10 @@ func validateSchema(compiler *jsonschema.Compiler, path string) error {
7269
return fmt.Errorf("invalid JSON: %w", err)
7370
}
7471

72+
// Create compiler for this validation
73+
compiler := jsonschema.NewCompiler()
74+
compiler.Draft = jsonschema.Draft7
75+
7576
// For registry-schema.json, we need to register the base schema it references
7677
if strings.Contains(path, "registry-schema.json") {
7778
basePath := filepath.Join(filepath.Dir(path), "schema.json")

0 commit comments

Comments
 (0)