3
3
from typing import Iterable
4
4
5
5
from openapi_core .exceptions import OpenAPIError
6
+ from openapi_core .spec import Spec
7
+ from openapi_core .unmarshalling .schemas .exceptions import ValidateError
8
+ from openapi_core .validation .exceptions import ValidationError
6
9
from openapi_core .validation .request .datatypes import Parameters
7
- from openapi_core .validation .request .protocols import Request
8
10
9
11
10
12
@dataclass
11
13
class ParametersError (Exception ):
12
14
parameters : Parameters
13
- errors : Iterable [Exception ]
15
+ errors : Iterable [OpenAPIError ]
14
16
15
17
@property
16
- def context (self ) -> Iterable [Exception ]:
18
+ def context (self ) -> Iterable [OpenAPIError ]:
17
19
warnings .warn (
18
20
"context property of ParametersError is deprecated. "
19
21
"Use errors instead." ,
@@ -22,11 +24,20 @@ def context(self) -> Iterable[Exception]:
22
24
return self .errors
23
25
24
26
25
- class OpenAPIRequestBodyError (OpenAPIError ):
26
- pass
27
+ class RequestError (ValidationError ):
28
+ """Request error"""
29
+
30
+
31
+ class RequestBodyError (RequestError ):
32
+ def __str__ (self ) -> str :
33
+ return "Request body error"
27
34
28
35
29
- class MissingRequestBodyError (OpenAPIRequestBodyError ):
36
+ class InvalidRequestBody (RequestBodyError , ValidateError ):
37
+ """Invalid request body"""
38
+
39
+
40
+ class MissingRequestBodyError (RequestBodyError ):
30
41
"""Missing request body error"""
31
42
32
43
@@ -38,3 +49,43 @@ def __str__(self) -> str:
38
49
class MissingRequiredRequestBody (MissingRequestBodyError ):
39
50
def __str__ (self ) -> str :
40
51
return "Missing required request body"
52
+
53
+
54
+ @dataclass
55
+ class ParameterError (RequestError ):
56
+ name : str
57
+ location : str
58
+
59
+ @classmethod
60
+ def from_spec (cls , spec : Spec ) -> "ParameterError" :
61
+ return cls (spec ["name" ], spec ["in" ])
62
+
63
+ def __str__ (self ) -> str :
64
+ return f"{ self .location .title ()} parameter error: { self .name } "
65
+
66
+
67
+ class InvalidParameter (ParameterError , ValidateError ):
68
+ def __str__ (self ) -> str :
69
+ return f"Invalid { self .location } parameter: { self .name } "
70
+
71
+
72
+ class MissingParameterError (ParameterError ):
73
+ """Missing parameter error"""
74
+
75
+
76
+ class MissingParameter (MissingParameterError ):
77
+ def __str__ (self ) -> str :
78
+ return f"Missing { self .location } parameter: { self .name } "
79
+
80
+
81
+ class MissingRequiredParameter (MissingParameterError ):
82
+ def __str__ (self ) -> str :
83
+ return f"Missing required { self .location } parameter: { self .name } "
84
+
85
+
86
+ class SecurityError (RequestError ):
87
+ pass
88
+
89
+
90
+ class InvalidSecurity (SecurityError , ValidateError ):
91
+ """Invalid security"""
0 commit comments