Skip to content

Commit 9ea9ecd

Browse files
Generate logs
1 parent 875e273 commit 9ea9ecd

10 files changed

Lines changed: 66 additions & 42 deletions

services/logs/oas_commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0e64886dd0847341800d7191ed193b75413be998
1+
0867dbbb09a8032415dc6debe18bc392bd58ba42

services/logs/src/stackit/logs/api_client.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class ApiClient:
6666
"date": datetime.date,
6767
"datetime": datetime.datetime,
6868
"decimal": decimal.Decimal,
69+
"UUID": uuid.UUID,
6970
"object": object,
7071
}
7172
_pool = None
@@ -265,7 +266,7 @@ def response_deserialize(
265266
response_text = None
266267
return_data = None
267268
try:
268-
if response_type == "bytearray":
269+
if response_type in ("bytearray", "bytes"):
269270
return_data = response_data.data
270271
elif response_type == "file":
271272
return_data = self.__deserialize_file(response_data)
@@ -326,25 +327,20 @@ def sanitize_for_serialization(self, obj):
326327
return obj.isoformat()
327328
elif isinstance(obj, decimal.Decimal):
328329
return str(obj)
329-
330330
elif isinstance(obj, dict):
331-
obj_dict = obj
331+
return {key: self.sanitize_for_serialization(val) for key, val in obj.items()}
332+
333+
# Convert model obj to dict except
334+
# attributes `openapi_types`, `attribute_map`
335+
# and attributes which value is not None.
336+
# Convert attribute name to json key in
337+
# model definition for request.
338+
if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")):
339+
obj_dict = obj.to_dict()
332340
else:
333-
# Convert model obj to dict except
334-
# attributes `openapi_types`, `attribute_map`
335-
# and attributes which value is not None.
336-
# Convert attribute name to json key in
337-
# model definition for request.
338-
if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): # noqa: B009
339-
obj_dict = obj.to_dict()
340-
else:
341-
obj_dict = obj.__dict__
342-
343-
if isinstance(obj_dict, list):
344-
# here we handle instances that can either be a list or something else, and only became a real list by calling to_dict() # noqa: E501
345-
return self.sanitize_for_serialization(obj_dict)
341+
obj_dict = obj.__dict__
346342

347-
return {key: self.sanitize_for_serialization(val) for key, val in obj_dict.items()}
343+
return self.sanitize_for_serialization(obj_dict)
348344

349345
def deserialize(self, response_text: str, response_type: str, content_type: Optional[str]):
350346
"""Deserializes response into an object.
@@ -417,6 +413,8 @@ def __deserialize(self, data, klass):
417413
return self.__deserialize_datetime(data)
418414
elif klass is decimal.Decimal:
419415
return decimal.Decimal(data)
416+
elif klass is uuid.UUID:
417+
return uuid.UUID(data)
420418
elif issubclass(klass, Enum):
421419
return self.__deserialize_enum(data, klass)
422420
else:

services/logs/src/stackit/logs/models/access_token.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
StrictStr,
2929
field_validator,
3030
)
31+
from pydantic_core import to_jsonable_python
3132
from typing_extensions import Annotated, Self
3233

3334

@@ -70,6 +71,9 @@ class AccessToken(BaseModel):
7071
@field_validator("display_name")
7172
def display_name_validate_regular_expression(cls, value):
7273
"""Validates the regular expression"""
74+
if not isinstance(value, str):
75+
value = str(value)
76+
7377
if not re.match(r"^[a-zA-Z][\w -]*$", value):
7478
raise ValueError(r"must validate the regular expression /^[a-zA-Z][\w -]*$/")
7579
return value
@@ -103,7 +107,8 @@ def valid_until_change_year_zero_to_one(cls, value):
103107
return value
104108

105109
model_config = ConfigDict(
106-
populate_by_name=True,
110+
validate_by_name=True,
111+
validate_by_alias=True,
107112
validate_assignment=True,
108113
protected_namespaces=(),
109114
)
@@ -114,8 +119,7 @@ def to_str(self) -> str:
114119

115120
def to_json(self) -> str:
116121
"""Returns the JSON representation of the model using alias"""
117-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
118-
return json.dumps(self.to_dict())
122+
return json.dumps(to_jsonable_python(self.to_dict()))
119123

120124
@classmethod
121125
def from_json(cls, json_str: str) -> Optional[Self]:

services/logs/src/stackit/logs/models/access_token_list.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import Any, ClassVar, Dict, List, Optional, Set
1919

2020
from pydantic import BaseModel, ConfigDict
21+
from pydantic_core import to_jsonable_python
2122
from typing_extensions import Self
2223

2324
from stackit.logs.models.access_token import AccessToken
@@ -32,7 +33,8 @@ class AccessTokenList(BaseModel):
3233
__properties: ClassVar[List[str]] = ["tokens"]
3334

3435
model_config = ConfigDict(
35-
populate_by_name=True,
36+
validate_by_name=True,
37+
validate_by_alias=True,
3638
validate_assignment=True,
3739
protected_namespaces=(),
3840
)
@@ -43,8 +45,7 @@ def to_str(self) -> str:
4345

4446
def to_json(self) -> str:
4547
"""Returns the JSON representation of the model using alias"""
46-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
47-
return json.dumps(self.to_dict())
48+
return json.dumps(to_jsonable_python(self.to_dict()))
4849

4950
@classmethod
5051
def from_json(cls, json_str: str) -> Optional[Self]:

services/logs/src/stackit/logs/models/create_access_token_payload.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425

@@ -42,6 +43,9 @@ class CreateAccessTokenPayload(BaseModel):
4243
@field_validator("display_name")
4344
def display_name_validate_regular_expression(cls, value):
4445
"""Validates the regular expression"""
46+
if not isinstance(value, str):
47+
value = str(value)
48+
4549
if not re.match(r"^[a-zA-Z][\w -]*$", value):
4650
raise ValueError(r"must validate the regular expression /^[a-zA-Z][\w -]*$/")
4751
return value
@@ -55,7 +59,8 @@ def permissions_validate_enum(cls, value):
5559
return value
5660

5761
model_config = ConfigDict(
58-
populate_by_name=True,
62+
validate_by_name=True,
63+
validate_by_alias=True,
5964
validate_assignment=True,
6065
protected_namespaces=(),
6166
)
@@ -66,8 +71,7 @@ def to_str(self) -> str:
6671

6772
def to_json(self) -> str:
6873
"""Returns the JSON representation of the model using alias"""
69-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
70-
return json.dumps(self.to_dict())
74+
return json.dumps(to_jsonable_python(self.to_dict()))
7175

7276
@classmethod
7377
def from_json(cls, json_str: str) -> Optional[Self]:

services/logs/src/stackit/logs/models/create_logs_instance_payload.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425

@@ -42,12 +43,16 @@ class CreateLogsInstancePayload(BaseModel):
4243
@field_validator("display_name")
4344
def display_name_validate_regular_expression(cls, value):
4445
"""Validates the regular expression"""
46+
if not isinstance(value, str):
47+
value = str(value)
48+
4549
if not re.match(r"^[a-zA-Z][\w -]*$", value):
4650
raise ValueError(r"must validate the regular expression /^[a-zA-Z][\w -]*$/")
4751
return value
4852

4953
model_config = ConfigDict(
50-
populate_by_name=True,
54+
validate_by_name=True,
55+
validate_by_alias=True,
5156
validate_assignment=True,
5257
protected_namespaces=(),
5358
)
@@ -58,8 +63,7 @@ def to_str(self) -> str:
5863

5964
def to_json(self) -> str:
6065
"""Returns the JSON representation of the model using alias"""
61-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
62-
return json.dumps(self.to_dict())
66+
return json.dumps(to_jsonable_python(self.to_dict()))
6367

6468
@classmethod
6569
def from_json(cls, json_str: str) -> Optional[Self]:

services/logs/src/stackit/logs/models/logs_instance.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from uuid import UUID
2222

2323
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
24+
from pydantic_core import to_jsonable_python
2425
from typing_extensions import Annotated, Self
2526

2627

@@ -88,6 +89,9 @@ def created_change_year_zero_to_one(cls, value):
8889
@field_validator("display_name")
8990
def display_name_validate_regular_expression(cls, value):
9091
"""Validates the regular expression"""
92+
if not isinstance(value, str):
93+
value = str(value)
94+
9195
if not re.match(r"^[a-zA-Z][\w -]*$", value):
9296
raise ValueError(r"must validate the regular expression /^[a-zA-Z][\w -]*$/")
9397
return value
@@ -100,7 +104,8 @@ def status_validate_enum(cls, value):
100104
return value
101105

102106
model_config = ConfigDict(
103-
populate_by_name=True,
107+
validate_by_name=True,
108+
validate_by_alias=True,
104109
validate_assignment=True,
105110
protected_namespaces=(),
106111
)
@@ -111,8 +116,7 @@ def to_str(self) -> str:
111116

112117
def to_json(self) -> str:
113118
"""Returns the JSON representation of the model using alias"""
114-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
115-
return json.dumps(self.to_dict())
119+
return json.dumps(to_jsonable_python(self.to_dict()))
116120

117121
@classmethod
118122
def from_json(cls, json_str: str) -> Optional[Self]:

services/logs/src/stackit/logs/models/logs_instances_list.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import Any, ClassVar, Dict, List, Optional, Set
1919

2020
from pydantic import BaseModel, ConfigDict
21+
from pydantic_core import to_jsonable_python
2122
from typing_extensions import Self
2223

2324
from stackit.logs.models.logs_instance import LogsInstance
@@ -32,7 +33,8 @@ class LogsInstancesList(BaseModel):
3233
__properties: ClassVar[List[str]] = ["instances"]
3334

3435
model_config = ConfigDict(
35-
populate_by_name=True,
36+
validate_by_name=True,
37+
validate_by_alias=True,
3638
validate_assignment=True,
3739
protected_namespaces=(),
3840
)
@@ -43,8 +45,7 @@ def to_str(self) -> str:
4345

4446
def to_json(self) -> str:
4547
"""Returns the JSON representation of the model using alias"""
46-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
47-
return json.dumps(self.to_dict())
48+
return json.dumps(to_jsonable_python(self.to_dict()))
4849

4950
@classmethod
5051
def from_json(cls, json_str: str) -> Optional[Self]:

services/logs/src/stackit/logs/models/update_access_token_payload.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, Field, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425

@@ -41,12 +42,16 @@ def display_name_validate_regular_expression(cls, value):
4142
if value is None:
4243
return value
4344

45+
if not isinstance(value, str):
46+
value = str(value)
47+
4448
if not re.match(r"^[a-zA-Z][\w -]*$", value):
4549
raise ValueError(r"must validate the regular expression /^[a-zA-Z][\w -]*$/")
4650
return value
4751

4852
model_config = ConfigDict(
49-
populate_by_name=True,
53+
validate_by_name=True,
54+
validate_by_alias=True,
5055
validate_assignment=True,
5156
protected_namespaces=(),
5257
)
@@ -57,8 +62,7 @@ def to_str(self) -> str:
5762

5863
def to_json(self) -> str:
5964
"""Returns the JSON representation of the model using alias"""
60-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
61-
return json.dumps(self.to_dict())
65+
return json.dumps(to_jsonable_python(self.to_dict()))
6266

6367
@classmethod
6468
def from_json(cls, json_str: str) -> Optional[Self]:

services/logs/src/stackit/logs/models/update_logs_instance_payload.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425

@@ -45,12 +46,16 @@ def display_name_validate_regular_expression(cls, value):
4546
if value is None:
4647
return value
4748

49+
if not isinstance(value, str):
50+
value = str(value)
51+
4852
if not re.match(r"^[a-zA-Z][\w -]*$", value):
4953
raise ValueError(r"must validate the regular expression /^[a-zA-Z][\w -]*$/")
5054
return value
5155

5256
model_config = ConfigDict(
53-
populate_by_name=True,
57+
validate_by_name=True,
58+
validate_by_alias=True,
5459
validate_assignment=True,
5560
protected_namespaces=(),
5661
)
@@ -61,8 +66,7 @@ def to_str(self) -> str:
6166

6267
def to_json(self) -> str:
6368
"""Returns the JSON representation of the model using alias"""
64-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
65-
return json.dumps(self.to_dict())
69+
return json.dumps(to_jsonable_python(self.to_dict()))
6670

6771
@classmethod
6872
def from_json(cls, json_str: str) -> Optional[Self]:

0 commit comments

Comments
 (0)