1
1
"""OpenAPI core validation response validators module"""
2
2
from openapi_core .casting .schemas .exceptions import CastError
3
3
from openapi_core .deserializing .exceptions import DeserializeError
4
- from openapi_core .schema .responses .exceptions import (
5
- InvalidResponse , MissingResponseContent ,
6
- )
4
+ from openapi_core .schema .responses .exceptions import MissingResponseContent
7
5
from openapi_core .templating .media_types .exceptions import MediaTypeFinderError
8
6
from openapi_core .templating .paths .exceptions import PathError
7
+ from openapi_core .templating .responses .exceptions import ResponseFinderError
9
8
from openapi_core .unmarshalling .schemas .enums import UnmarshalContext
10
9
from openapi_core .unmarshalling .schemas .exceptions import (
11
10
UnmarshalError , ValidateError ,
@@ -27,7 +26,7 @@ def validate(self, request, response):
27
26
operation_response = self ._get_operation_response (
28
27
operation , response )
29
28
# don't process if operation errors
30
- except InvalidResponse as exc :
29
+ except ResponseFinderError as exc :
31
30
return ResponseValidationResult (errors = [exc , ])
32
31
33
32
data , data_errors = self ._get_data (response , operation_response )
@@ -43,7 +42,9 @@ def validate(self, request, response):
43
42
)
44
43
45
44
def _get_operation_response (self , operation , response ):
46
- return operation .get_response (str (response .status_code ))
45
+ from openapi_core .templating .responses .finders import ResponseFinder
46
+ finder = ResponseFinder (operation .responses )
47
+ return finder .find (str (response .status_code ))
47
48
48
49
def _validate_data (self , request , response ):
49
50
try :
@@ -56,7 +57,7 @@ def _validate_data(self, request, response):
56
57
operation_response = self ._get_operation_response (
57
58
operation , response )
58
59
# don't process if operation errors
59
- except InvalidResponse as exc :
60
+ except ResponseFinderError as exc :
60
61
return ResponseValidationResult (errors = [exc , ])
61
62
62
63
data , data_errors = self ._get_data (response , operation_response )
0 commit comments