Skip to content

Commit

Permalink
Merge pull request #10 from MinBZK/fix/validate
Browse files Browse the repository at this point in the history
Add schema validation to pre-commit hook
  • Loading branch information
ravimeijerrig authored Jun 28, 2024
2 parents 626ca0d + 04a3973 commit e9148a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ repos:
hooks:
- id: ruff
- id: ruff-format
- repo: local
hooks:
- id: validate-schema
name: validate schema
entry: ./script/validate schema.json
language: python
additional_dependencies: [jsonschema, pyyaml]
files: ^instruments/


ci:
autofix_prs: false
Expand Down
22 changes: 12 additions & 10 deletions script/validate
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import jsonschema
import yaml
from jsonschema import validate

# Load the YAML file
with open(sys.argv[2], "r") as yaml_file:
data = yaml.safe_load(yaml_file)

# Load the JSON schema
with open(sys.argv[1], "r") as schema_file:
schema = json.load(schema_file)

# Validate the data
try:
validate(instance=data, schema=schema)
print("Validation successful.")
except jsonschema.exceptions.ValidationError as err:
print("Validation error:", err.message)
for f in sys.argv[2:]:
# Load the YAML file
with open(f, "r") as yaml_file:
data = yaml.safe_load(yaml_file)

# Validate the data
try:
validate(instance=data, schema=schema)
print(f"Validation of '{f}' successful.")
except jsonschema.exceptions.ValidationError as err:
print(f"Validation error in '{f}': {err.message}")
sys.exit(1)

0 comments on commit e9148a8

Please sign in to comment.