fix: resolve CI/CD test and lint failures
This commit is contained in:
@@ -11,11 +11,7 @@ from .parsers import load_data
|
||||
class SchemaValidator:
|
||||
"""Handle JSON Schema validation for data files."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
schema: Optional[Dict[str, Any]] = None,
|
||||
schema_file: Optional[str] = None,
|
||||
):
|
||||
def __init__(self, schema: Optional[Dict[str, Any]] = None, schema_file: Optional[str] = None):
|
||||
"""Initialize validator with optional schema."""
|
||||
self.schema = None
|
||||
self.validator_class = None
|
||||
@@ -27,12 +23,11 @@ class SchemaValidator:
|
||||
def set_schema(self, schema: Dict[str, Any]) -> None:
|
||||
"""Set the validation schema."""
|
||||
self.schema = schema
|
||||
draft = schema.get("$schema", "http://json-schema.org/draft-07/schema#")
|
||||
draft = schema.get("$", "http://json-schema.org/draft-07/schema#")
|
||||
if "draft-07" in draft or "draft-07" in draft:
|
||||
self.validator_class = Draft7Validator
|
||||
elif "draft-2019-09" in draft:
|
||||
from jsonschema import Draft201909Validator
|
||||
|
||||
self.validator_class = Draft201909Validator
|
||||
else:
|
||||
self.validator_class = Draft7Validator
|
||||
@@ -42,9 +37,7 @@ class SchemaValidator:
|
||||
schema_data = load_data(schema_file)
|
||||
self.set_schema(schema_data)
|
||||
|
||||
def validate(
|
||||
self, data: Any, raise_on_error: bool = False
|
||||
) -> List[ValidationError]:
|
||||
def validate(self, data: Any, raise_on_error: bool = False) -> List[ValidationError]:
|
||||
"""Validate data against the schema."""
|
||||
if self.schema is None:
|
||||
raise ValueError("No schema has been set for validation")
|
||||
@@ -54,9 +47,7 @@ class SchemaValidator:
|
||||
raise ValidationError(errors[0].message)
|
||||
return errors
|
||||
|
||||
def validate_file(
|
||||
self, file_path: str, format: Optional[str] = None
|
||||
) -> List[ValidationError]:
|
||||
def validate_file(self, file_path: str, format: Optional[str] = None) -> List[ValidationError]:
|
||||
"""Validate a file against the schema."""
|
||||
data = load_data(file_path, format)
|
||||
return self.validate(data)
|
||||
@@ -70,9 +61,7 @@ class SchemaValidator:
|
||||
return messages
|
||||
|
||||
|
||||
def validate_data(
|
||||
data: Any, schema: Dict[str, Any]
|
||||
) -> tuple[bool, List[str]]:
|
||||
def validate_data(data: Any, schema: Dict[str, Any]) -> tuple[bool, List[str]]:
|
||||
"""Validate data against a schema and return success status and error messages."""
|
||||
validator = SchemaValidator(schema=schema)
|
||||
errors = validator.validate(data)
|
||||
@@ -80,9 +69,7 @@ def validate_data(
|
||||
return len(errors) == 0, messages
|
||||
|
||||
|
||||
def validate_file(
|
||||
file_path: str, schema_file: str, format: Optional[str] = None
|
||||
) -> tuple[bool, List[str]]:
|
||||
def validate_file(file_path: str, schema_file: str, format: Optional[str] = None) -> tuple[bool, List[str]]:
|
||||
"""Validate a file against a schema file."""
|
||||
validator = SchemaValidator(schema_file=schema_file)
|
||||
errors = validator.validate_file(file_path, format)
|
||||
|
||||
Reference in New Issue
Block a user