@@ -192,6 +192,67 @@ def test_request_validator_error_message_includes_cause_details() -> None:
192192 assert "'30' is not of type 'integer'" in error_message
193193
194194
195+ def test_request_validator_error_details_are_structured () -> None :
196+ spec = _spec_schema_path ()
197+ validator = V30RequestValidator (spec )
198+
199+ request_json = {
200+ "id" : "123e4567-e89b-12d3-a456-426614174000" ,
201+ "username" : "Test User" ,
202+ "age" : "30" ,
203+ }
204+ request = MockRequest (
205+ "http://example.com" ,
206+ "post" ,
207+ "/users" ,
208+ content_type = "application/json" ,
209+ data = json .dumps (request_json ).encode ("utf-8" ),
210+ )
211+
212+ with pytest .raises (InvalidRequestBody ) as exc_info :
213+ validator .validate (request )
214+
215+ details = exc_info .value .details
216+ assert details ["error_type" ] == "InvalidRequestBody"
217+ assert details ["cause_type" ] == "InvalidSchemaValue"
218+ assert details ["schema_errors" ] == [
219+ {
220+ "message" : "'30' is not of type 'integer'" ,
221+ "path" : ["age" ],
222+ }
223+ ]
224+
225+
226+ def test_response_validator_error_details_are_structured () -> None :
227+ spec = _spec_schema_path ()
228+ validator = V30ResponseValidator (spec )
229+
230+ request = MockRequest ("http://example.com" , "get" , "/users" )
231+ response_json = {
232+ "id" : "123e4567-e89b-12d3-a456-426614174000" ,
233+ "username" : "Test User" ,
234+ "age" : "30" ,
235+ }
236+ response = MockResponse (
237+ json .dumps (response_json ).encode ("utf-8" ),
238+ status_code = 200 ,
239+ content_type = "application/json" ,
240+ )
241+
242+ with pytest .raises (InvalidData ) as exc_info :
243+ validator .validate (request , response )
244+
245+ details = exc_info .value .details
246+ assert details ["error_type" ] == "InvalidData"
247+ assert details ["cause_type" ] == "InvalidSchemaValue"
248+ assert details ["schema_errors" ] == [
249+ {
250+ "message" : "'30' is not of type 'integer'" ,
251+ "path" : ["age" ],
252+ }
253+ ]
254+
255+
195256def test_response_validator_strict_json_nested_types () -> None :
196257 """Test that nested JSON structures (arrays, objects) remain strict."""
197258 spec_dict = {
0 commit comments