Skip to content

Commit

Permalink
Refactor: Add annotations to schema validator
Browse files Browse the repository at this point in the history
Issue: RELENG-4933
Signed-off-by: Andrew Grimberg <agrimberg@linuxfoundation.org>
Change-Id: I1b13c1ad1ad825cf29718dd15c0cc56c8a4a55cc
tykeal committed Oct 10, 2023
1 parent 92af662 commit f69da9a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lftools/schema.py
Original file line number Diff line number Diff line change
@@ -9,33 +9,36 @@
##############################################################################
"""Verify YAML Schema."""

from __future__ import print_function
from __future__ import annotations, print_function

import logging
from typing import Dict

import jsonschema
import yaml


def check_schema_file(yamlfile, schemafile):
def check_schema_file(yamlfile: str, schemafile: str) -> None:
"""Verify YAML Schema.
YAMLFILE: Release YAML file to be validated.
SCHEMAFILE: SCHEMA file to validate against.
"""
with open(yamlfile) as _:
yaml_file = yaml.safe_load(_)
yaml_file: Dict = yaml.safe_load(_)

with open(schemafile) as _:
schema_file = yaml.safe_load(_)
schema_file: Dict = yaml.safe_load(_)

# Load the schema
validation = jsonschema.Draft4Validator(schema_file, format_checker=jsonschema.FormatChecker())
validation: jsonschema.Draft4Validator = jsonschema.Draft4Validator(
schema_file, format_checker=jsonschema.FormatChecker()
)

validation.iter_errors(yaml_file)
# Look for errors
errors = 0
errors: int = 0
for error in validation.iter_errors(yaml_file):
errors += 1
logging.error(error)

0 comments on commit f69da9a

Please sign in to comment.