1616
1717
1818if TYPE_CHECKING :
19- from collections import deque
19+ from collections . abc import Sequence
2020
2121
22- def to_path (schema_path : deque [Any ]) -> str :
22+ def to_path (schema_path : Sequence [Any ]) -> str :
2323 """Flatten a path to a dot delimited string.
2424
2525 Args:
@@ -31,7 +31,7 @@ def to_path(schema_path: deque[Any]) -> str:
3131 return "." .join (str (index ) for index in schema_path )
3232
3333
34- def json_path (absolute_path : deque [Any ]) -> str :
34+ def json_path (absolute_path : Sequence [Any ]) -> str :
3535 """Flatten a data path to a dot delimited string.
3636
3737 Args:
@@ -97,7 +97,7 @@ def validate(schema: str | dict[str, Any], data: dict[str, Any]) -> list[JsonSch
9797
9898 if isinstance (schema , str ):
9999 schema = json .loads (schema )
100- if isinstance (schema , bool ):
100+ if isinstance (schema , ( bool , str ) ):
101101 msg = "Unexpected schema data."
102102 raise TypeError (msg )
103103 validator = validator_for (schema )
@@ -124,15 +124,19 @@ def validate(schema: str | dict[str, Any], data: dict[str, Any]) -> list[JsonSch
124124
125125 for validation_error in validation_errors :
126126 if isinstance (validation_error , ValidationError ):
127+ if isinstance (validation_error .absolute_path , bool ):
128+ path = str (validation_error .absolute_path )
129+ else :
130+ path = to_path (validation_error .absolute_path )
127131 error = JsonSchemaError (
128132 message = validation_error .message ,
129- data_path = to_path ( validation_error . absolute_path ) ,
130- json_path = json_path ( validation_error . absolute_path ) ,
133+ data_path = path ,
134+ json_path = path ,
131135 schema_path = to_path (validation_error .relative_schema_path ),
132- relative_schema = validation_error .schema ,
133- expected = validation_error .validator_value ,
134- validator = validation_error .validator ,
135- found = validation_error .instance ,
136+ relative_schema = str ( validation_error .schema ) ,
137+ expected = str ( validation_error .validator_value ) ,
138+ validator = str ( validation_error .validator ) ,
139+ found = str ( validation_error .instance ) ,
136140 )
137141 errors .append (error )
138142 return errors
0 commit comments