forked from openapi-generators/openapi-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
50 lines (39 loc) · 1.22 KB
/
__init__.py
File metadata and controls
50 lines (39 loc) · 1.22 KB
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
__all__ = [
"MediaType",
"OpenAPI",
"Operation",
"Parameter",
"PathItem",
"Reference",
"RequestBody",
"Response",
"Responses",
"Schema",
]
import re
from typing import Callable, Iterator
from .openapi_schema_pydantic import MediaType
from .openapi_schema_pydantic import OpenAPI as _OpenAPI
from .openapi_schema_pydantic import Operation, Parameter, PathItem, Reference, RequestBody, Response, Responses, Schema
regex = re.compile(r"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)")
class SemVer:
def __init__(self, str_value: str) -> None:
self.str_value = str_value
if not isinstance(str_value, str):
raise TypeError("string required")
m = regex.fullmatch(str_value)
if not m:
raise ValueError("invalid semantic versioning format")
self.major = int(m.group(1))
self.minor = int(m.group(2))
self.patch = int(m.group(3))
@classmethod
def __get_validators__(cls) -> Iterator[Callable[[str], "SemVer"]]:
yield cls.validate
@classmethod
def validate(cls, v: str) -> "SemVer":
return cls(v)
def __str__(self) -> str:
return self.str_value
class OpenAPI(_OpenAPI):
openapi: SemVer