fix: resolve CI linting and type checking issues
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
"""Schema inference and validation module."""
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from pydantic import BaseModel, ValidationError, field_validator
|
||||
from pydantic import BaseModel, field_validator
|
||||
|
||||
|
||||
class SchemaType:
|
||||
@@ -57,6 +57,10 @@ class InferredSchema:
|
||||
description: str = ""
|
||||
items: Optional[SchemaProperty] = None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if self.properties is None:
|
||||
self.properties = []
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""Convert to dictionary."""
|
||||
result: Dict[str, Any] = {
|
||||
@@ -199,7 +203,7 @@ class SchemaValidator:
|
||||
|
||||
def validate(self, data: Any) -> Tuple[bool, List[str]]:
|
||||
"""Validate data against schema."""
|
||||
errors = []
|
||||
errors: List[str] = []
|
||||
is_valid = self._validate_value(data, self.schema, "", errors)
|
||||
return is_valid, errors
|
||||
|
||||
@@ -226,9 +230,8 @@ class SchemaValidator:
|
||||
prop_path = f"{path}.{prop.name}" if path else prop.name
|
||||
if prop.name in value:
|
||||
prop_value = value[prop.name]
|
||||
prop_schema = InferredSchema(
|
||||
root_type=prop.type, properties=prop.properties
|
||||
)
|
||||
prop_props: List[SchemaProperty] = prop.properties if prop.properties else []
|
||||
prop_schema = InferredSchema(root_type=prop.type, properties=prop_props) # type: ignore[arg-type]
|
||||
self._validate_value(prop_value, prop_schema, prop_path, errors)
|
||||
elif prop.required:
|
||||
errors.append(f"{prop_path}: required property missing")
|
||||
@@ -238,10 +241,8 @@ class SchemaValidator:
|
||||
errors.append(f"{path}: expected array, got {actual_type}")
|
||||
return False
|
||||
if isinstance(value, list) and schema.items:
|
||||
item_schema = InferredSchema(
|
||||
root_type=schema.items.type,
|
||||
properties=schema.items.properties if schema.items.properties else None,
|
||||
)
|
||||
item_props: List[SchemaProperty] = schema.items.properties if schema.items.properties else []
|
||||
item_schema = InferredSchema(root_type=schema.items.type, properties=item_props) # type: ignore[arg-type]
|
||||
for i, item in enumerate(value):
|
||||
self._validate_value(item, item_schema, f"{path}[{i}]", errors)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user