Skip to content

Commit 445b763

Browse files
authored
Merge pull request #529 from python-openapi/feature/rename-validation-errors
Rename validation errors
2 parents ca42982 + 9b0f488 commit 445b763

File tree

13 files changed

+88
-78
lines changed

13 files changed

+88
-78
lines changed

openapi_core/unmarshalling/request/unmarshallers.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@
4545
from openapi_core.util import chainiters
4646
from openapi_core.validation.request.exceptions import MissingRequestBody
4747
from openapi_core.validation.request.exceptions import ParametersError
48-
from openapi_core.validation.request.exceptions import RequestBodyError
49-
from openapi_core.validation.request.exceptions import SecurityError
48+
from openapi_core.validation.request.exceptions import (
49+
RequestBodyValidationError,
50+
)
51+
from openapi_core.validation.request.exceptions import SecurityValidationError
5052
from openapi_core.validation.request.validators import APICallRequestValidator
5153
from openapi_core.validation.request.validators import BaseRequestValidator
5254
from openapi_core.validation.request.validators import V30RequestBodyValidator
@@ -137,7 +139,7 @@ def _unmarshal(
137139
) -> RequestUnmarshalResult:
138140
try:
139141
security = self._get_security(request.parameters, operation)
140-
except SecurityError as exc:
142+
except SecurityValidationError as exc:
141143
return RequestUnmarshalResult(errors=[exc])
142144

143145
try:
@@ -153,7 +155,7 @@ def _unmarshal(
153155
except MissingRequestBody:
154156
body = None
155157
body_errors = []
156-
except RequestBodyError as exc:
158+
except RequestBodyValidationError as exc:
157159
body = None
158160
body_errors = [exc]
159161
else:
@@ -175,7 +177,7 @@ def _unmarshal_body(
175177
except MissingRequestBody:
176178
body = None
177179
errors = []
178-
except RequestBodyError as exc:
180+
except RequestBodyValidationError as exc:
179181
body = None
180182
errors = [exc]
181183
else:
@@ -207,7 +209,7 @@ def _unmarshal_security(
207209
) -> RequestUnmarshalResult:
208210
try:
209211
security = self._get_security(request.parameters, operation)
210-
except SecurityError as exc:
212+
except SecurityValidationError as exc:
211213
return RequestUnmarshalResult(errors=[exc])
212214

213215
return RequestUnmarshalResult(

openapi_core/unmarshalling/response/unmarshallers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626
from openapi_core.unmarshalling.unmarshallers import BaseUnmarshaller
2727
from openapi_core.util import chainiters
28-
from openapi_core.validation.response.exceptions import DataError
28+
from openapi_core.validation.response.exceptions import DataValidationError
2929
from openapi_core.validation.response.exceptions import HeadersError
3030
from openapi_core.validation.response.validators import (
3131
APICallResponseValidator,
@@ -77,7 +77,7 @@ def _unmarshal(
7777
validated_data = self._get_data(
7878
response.data, response.mimetype, operation_response
7979
)
80-
except DataError as exc:
80+
except DataValidationError as exc:
8181
validated_data = None
8282
data_errors = [exc]
8383
else:
@@ -117,7 +117,7 @@ def _unmarshal_data(
117117
validated = self._get_data(
118118
response.data, response.mimetype, operation_response
119119
)
120-
except DataError as exc:
120+
except DataValidationError as exc:
121121
validated = None
122122
data_errors = [exc]
123123
else:

openapi_core/validation/request/exceptions.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ def context(self) -> Iterable[OpenAPIError]:
2424
return self.errors
2525

2626

27-
class RequestError(ValidationError):
28-
"""Request error"""
27+
class RequestValidationError(ValidationError):
28+
"""Request validation error"""
2929

3030

31-
class RequestBodyError(RequestError):
31+
class RequestBodyValidationError(RequestValidationError):
3232
def __str__(self) -> str:
33-
return "Request body error"
33+
return "Request body validation error"
3434

3535

36-
class InvalidRequestBody(RequestBodyError, ValidateError):
36+
class InvalidRequestBody(RequestBodyValidationError, ValidateError):
3737
"""Invalid request body"""
3838

3939

40-
class MissingRequestBodyError(RequestBodyError):
40+
class MissingRequestBodyError(RequestBodyValidationError):
4141
"""Missing request body error"""
4242

4343

@@ -52,24 +52,24 @@ def __str__(self) -> str:
5252

5353

5454
@dataclass
55-
class ParameterError(RequestError):
55+
class ParameterValidationError(RequestValidationError):
5656
name: str
5757
location: str
5858

5959
@classmethod
60-
def from_spec(cls, spec: Spec) -> "ParameterError":
60+
def from_spec(cls, spec: Spec) -> "ParameterValidationError":
6161
return cls(spec["name"], spec["in"])
6262

6363
def __str__(self) -> str:
6464
return f"{self.location.title()} parameter error: {self.name}"
6565

6666

67-
class InvalidParameter(ParameterError, ValidateError):
67+
class InvalidParameter(ParameterValidationError, ValidateError):
6868
def __str__(self) -> str:
6969
return f"Invalid {self.location} parameter: {self.name}"
7070

7171

72-
class MissingParameterError(ParameterError):
72+
class MissingParameterError(ParameterValidationError):
7373
"""Missing parameter error"""
7474

7575

@@ -83,9 +83,9 @@ def __str__(self) -> str:
8383
return f"Missing required {self.location} parameter: {self.name}"
8484

8585

86-
class SecurityError(RequestError):
86+
class SecurityValidationError(RequestValidationError):
8787
pass
8888

8989

90-
class InvalidSecurity(SecurityError, ValidateError):
90+
class InvalidSecurity(SecurityValidationError, ValidateError):
9191
"""Invalid security"""

openapi_core/validation/request/validators.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545
from openapi_core.validation.request.exceptions import (
4646
MissingRequiredRequestBody,
4747
)
48-
from openapi_core.validation.request.exceptions import ParameterError
4948
from openapi_core.validation.request.exceptions import ParametersError
50-
from openapi_core.validation.request.exceptions import RequestBodyError
51-
from openapi_core.validation.request.exceptions import SecurityError
49+
from openapi_core.validation.request.exceptions import ParameterValidationError
50+
from openapi_core.validation.request.exceptions import (
51+
RequestBodyValidationError,
52+
)
53+
from openapi_core.validation.request.exceptions import SecurityValidationError
5254
from openapi_core.validation.schemas import (
5355
oas30_write_schema_validators_factory,
5456
)
@@ -95,7 +97,7 @@ def _iter_errors(
9597
try:
9698
self._get_security(request.parameters, operation)
9799
# don't process if security errors
98-
except SecurityError as exc:
100+
except SecurityValidationError as exc:
99101
yield exc
100102
return
101103

@@ -106,15 +108,15 @@ def _iter_errors(
106108

107109
try:
108110
self._get_body(request.body, request.mimetype, operation)
109-
except RequestBodyError as exc:
111+
except RequestBodyValidationError as exc:
110112
yield exc
111113

112114
def _iter_body_errors(
113115
self, request: BaseRequest, operation: Spec
114116
) -> Iterator[Exception]:
115117
try:
116118
self._get_body(request.body, request.mimetype, operation)
117-
except RequestBodyError as exc:
119+
except RequestBodyValidationError as exc:
118120
yield exc
119121

120122
def _iter_parameters_errors(
@@ -130,7 +132,7 @@ def _iter_security_errors(
130132
) -> Iterator[Exception]:
131133
try:
132134
self._get_security(request.parameters, operation)
133-
except SecurityError as exc:
135+
except SecurityValidationError as exc:
134136
yield exc
135137

136138
def _get_parameters(
@@ -158,7 +160,7 @@ def _get_parameters(
158160
value = self._get_parameter(parameters, param)
159161
except MissingParameter:
160162
continue
161-
except ParameterError as exc:
163+
except ParameterValidationError as exc:
162164
errors.append(exc)
163165
continue
164166
else:
@@ -171,7 +173,7 @@ def _get_parameters(
171173
return validated
172174

173175
@ValidationErrorWrapper(
174-
ParameterError,
176+
ParameterValidationError,
175177
InvalidParameter,
176178
"from_spec",
177179
spec="param",
@@ -197,7 +199,7 @@ def _get_parameter(
197199
raise MissingRequiredParameter(name, param_location)
198200
raise MissingParameter(name, param_location)
199201

200-
@ValidationErrorWrapper(SecurityError, InvalidSecurity)
202+
@ValidationErrorWrapper(SecurityValidationError, InvalidSecurity)
201203
def _get_security(
202204
self, parameters: RequestParameters, operation: Spec
203205
) -> Optional[Dict[str, str]]:
@@ -236,7 +238,7 @@ def _get_security_value(
236238
security_provider = self.security_provider_factory.create(scheme)
237239
return security_provider(parameters)
238240

239-
@ValidationErrorWrapper(RequestBodyError, InvalidRequestBody)
241+
@ValidationErrorWrapper(RequestBodyValidationError, InvalidRequestBody)
240242
def _get_body(
241243
self, body: Optional[str], mimetype: str, operation: Spec
242244
) -> Any:

openapi_core/validation/response/exceptions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@ class HeadersError(Exception):
1414
context: Iterable[OpenAPIError]
1515

1616

17-
class ResponseError(ValidationError):
17+
class ResponseValidationError(ValidationError):
1818
"""Response error"""
1919

2020

21-
class DataError(ResponseError):
21+
class DataValidationError(ResponseValidationError):
2222
"""Data error"""
2323

2424

25-
class InvalidData(DataError, ValidateError):
25+
class InvalidData(DataValidationError, ValidateError):
2626
"""Invalid data"""
2727

2828

29-
class MissingData(DataError):
29+
class MissingData(DataValidationError):
3030
def __str__(self) -> str:
3131
return "Missing response data"
3232

3333

3434
@dataclass
35-
class HeaderError(ResponseError):
35+
class HeaderValidationError(ResponseValidationError):
3636
name: str
3737

3838

39-
class InvalidHeader(HeaderError, ValidateError):
39+
class InvalidHeader(HeaderValidationError, ValidateError):
4040
"""Invalid header"""
4141

4242

43-
class MissingHeaderError(HeaderError):
43+
class MissingHeaderError(HeaderValidationError):
4444
"""Missing header error"""
4545

4646

openapi_core/validation/response/validators.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
from openapi_core.templating.responses.exceptions import ResponseFinderError
1616
from openapi_core.validation.decorators import ValidationErrorWrapper
1717
from openapi_core.validation.exceptions import ValidationError
18-
from openapi_core.validation.response.exceptions import DataError
19-
from openapi_core.validation.response.exceptions import HeaderError
18+
from openapi_core.validation.response.exceptions import DataValidationError
2019
from openapi_core.validation.response.exceptions import HeadersError
20+
from openapi_core.validation.response.exceptions import HeaderValidationError
2121
from openapi_core.validation.response.exceptions import InvalidData
2222
from openapi_core.validation.response.exceptions import InvalidHeader
2323
from openapi_core.validation.response.exceptions import MissingData
@@ -52,7 +52,7 @@ def _iter_errors(
5252

5353
try:
5454
self._get_data(data, mimetype, operation_response)
55-
except DataError as exc:
55+
except DataValidationError as exc:
5656
yield exc
5757

5858
try:
@@ -74,7 +74,7 @@ def _iter_data_errors(
7474

7575
try:
7676
self._get_data(data, mimetype, operation_response)
77-
except DataError as exc:
77+
except DataValidationError as exc:
7878
yield exc
7979

8080
def _iter_headers_errors(
@@ -104,7 +104,7 @@ def _get_operation_response(
104104
finder = ResponseFinder(operation / "responses")
105105
return finder.find(str(status_code))
106106

107-
@ValidationErrorWrapper(DataError, InvalidData)
107+
@ValidationErrorWrapper(DataValidationError, InvalidData)
108108
def _get_data(
109109
self, data: str, mimetype: str, operation_response: Spec
110110
) -> Any:
@@ -151,7 +151,7 @@ def _get_headers(
151151

152152
return validated
153153

154-
@ValidationErrorWrapper(HeaderError, InvalidHeader, name="name")
154+
@ValidationErrorWrapper(HeaderValidationError, InvalidHeader, name="name")
155155
def _get_header(
156156
self, headers: Mapping[str, Any], name: str, header: Spec
157157
) -> Any:

0 commit comments

Comments
 (0)