16
16
17
17
18
18
if TYPE_CHECKING :
19
- from collections import deque
19
+ from collections . abc import Sequence
20
20
21
21
22
- def to_path (schema_path : deque [Any ]) -> str :
22
+ def to_path (schema_path : Sequence [Any ]) -> str :
23
23
"""Flatten a path to a dot delimited string.
24
24
25
25
Args:
@@ -31,7 +31,7 @@ def to_path(schema_path: deque[Any]) -> str:
31
31
return "." .join (str (index ) for index in schema_path )
32
32
33
33
34
- def json_path (absolute_path : deque [Any ]) -> str :
34
+ def json_path (absolute_path : Sequence [Any ]) -> str :
35
35
"""Flatten a data path to a dot delimited string.
36
36
37
37
Args:
@@ -97,7 +97,7 @@ def validate(schema: str | dict[str, Any], data: dict[str, Any]) -> list[JsonSch
97
97
98
98
if isinstance (schema , str ):
99
99
schema = json .loads (schema )
100
- if isinstance (schema , bool ):
100
+ if isinstance (schema , ( bool , str ) ):
101
101
msg = "Unexpected schema data."
102
102
raise TypeError (msg )
103
103
validator = validator_for (schema )
@@ -124,15 +124,19 @@ def validate(schema: str | dict[str, Any], data: dict[str, Any]) -> list[JsonSch
124
124
125
125
for validation_error in validation_errors :
126
126
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 )
127
131
error = JsonSchemaError (
128
132
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 ,
131
135
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 ) ,
136
140
)
137
141
errors .append (error )
138
142
return errors
0 commit comments