11"""OpenAPI core validation response validators module"""
22from openapi_core .casting .schemas .exceptions import CastError
33from 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
75from openapi_core .templating .media_types .exceptions import MediaTypeFinderError
86from openapi_core .templating .paths .exceptions import PathError
7+ from openapi_core .templating .responses .exceptions import ResponseFinderError
98from openapi_core .unmarshalling .schemas .enums import UnmarshalContext
109from openapi_core .unmarshalling .schemas .exceptions import (
1110 UnmarshalError , ValidateError ,
@@ -27,7 +26,7 @@ def validate(self, request, response):
2726 operation_response = self ._get_operation_response (
2827 operation , response )
2928 # don't process if operation errors
30- except InvalidResponse as exc :
29+ except ResponseFinderError as exc :
3130 return ResponseValidationResult (errors = [exc , ])
3231
3332 data , data_errors = self ._get_data (response , operation_response )
@@ -43,7 +42,9 @@ def validate(self, request, response):
4342 )
4443
4544 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 ))
4748
4849 def _validate_data (self , request , response ):
4950 try :
@@ -56,7 +57,7 @@ def _validate_data(self, request, response):
5657 operation_response = self ._get_operation_response (
5758 operation , response )
5859 # don't process if operation errors
59- except InvalidResponse as exc :
60+ except ResponseFinderError as exc :
6061 return ResponseValidationResult (errors = [exc , ])
6162
6263 data , data_errors = self ._get_data (response , operation_response )
0 commit comments