File: exceptions.py

package info (click to toggle)
python-openapi-core 0.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,104 kB
  • sloc: python: 19,979; makefile: 44
file content (82 lines) | stat: -rw-r--r-- 2,173 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from dataclasses import dataclass
from typing import Iterable

from jsonschema_path import SchemaPath

from openapi_core.datatypes import Parameters
from openapi_core.exceptions import OpenAPIError
from openapi_core.validation.exceptions import ValidationError
from openapi_core.validation.schemas.exceptions import ValidateError


@dataclass
class ParametersError(Exception):
    parameters: Parameters
    errors: Iterable[OpenAPIError]


class RequestValidationError(ValidationError):
    """Request validation error"""


class RequestBodyValidationError(RequestValidationError):
    def __str__(self) -> str:
        return "Request body validation error"


class InvalidRequestBody(RequestBodyValidationError, ValidateError):
    """Invalid request body"""


class MissingRequestBodyError(RequestBodyValidationError):
    """Missing request body error"""


class MissingRequestBody(MissingRequestBodyError):
    def __str__(self) -> str:
        return "Missing request body"


class MissingRequiredRequestBody(MissingRequestBodyError):
    def __str__(self) -> str:
        return "Missing required request body"


@dataclass
class ParameterValidationError(RequestValidationError):
    name: str
    location: str

    @classmethod
    def from_spec(cls, spec: SchemaPath) -> "ParameterValidationError":
        return cls(spec["name"], spec["in"])

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


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


class MissingParameterError(ParameterValidationError):
    """Missing parameter error"""


class MissingParameter(MissingParameterError):
    def __str__(self) -> str:
        return f"Missing {self.location} parameter: {self.name}"


class MissingRequiredParameter(MissingParameterError):
    def __str__(self) -> str:
        return f"Missing required {self.location} parameter: {self.name}"


class SecurityValidationError(RequestValidationError):
    pass


class InvalidSecurity(SecurityValidationError, ValidateError):
    """Invalid security"""