Skip to content

Commit 8a7bee2

Browse files
Generate resourcemanager
1 parent 875e273 commit 8a7bee2

22 files changed

Lines changed: 111 additions & 78 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1580d22d7dd90cfd56802bdda4a61795d1cb9813
1+
0867dbbb09a8032415dc6debe18bc392bd58ba42

services/resourcemanager/src/stackit/resourcemanager/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/resourcemanager/src/stackit/resourcemanager/models/container_search_result.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from uuid import UUID
2020

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

2425
from stackit.resourcemanager.models.lifecycle_state import LifecycleState
@@ -54,7 +55,8 @@ def container_type_validate_enum(cls, value):
5455
return value
5556

5657
model_config = ConfigDict(
57-
populate_by_name=True,
58+
validate_by_name=True,
59+
validate_by_alias=True,
5860
validate_assignment=True,
5961
protected_namespaces=(),
6062
)
@@ -65,8 +67,7 @@ def to_str(self) -> str:
6567

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

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

services/resourcemanager/src/stackit/resourcemanager/models/create_folder_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
from stackit.resourcemanager.models.member import Member
@@ -49,14 +50,18 @@ class CreateFolderPayload(BaseModel):
4950
@field_validator("name")
5051
def name_validate_regular_expression(cls, value):
5152
"""Validates the regular expression"""
53+
if not isinstance(value, str):
54+
value = str(value)
55+
5256
if not re.match(r"^[a-zA-ZäüöÄÜÖ0-9]( ?[a-zA-ZäüöÄÜÖß0-9_+&-]){0,39}$", value):
5357
raise ValueError(
5458
r"must validate the regular expression /^[a-zA-ZäüöÄÜÖ0-9]( ?[a-zA-ZäüöÄÜÖß0-9_+&-]){0,39}$/"
5559
)
5660
return value
5761

5862
model_config = ConfigDict(
59-
populate_by_name=True,
63+
validate_by_name=True,
64+
validate_by_alias=True,
6065
validate_assignment=True,
6166
protected_namespaces=(),
6267
)
@@ -67,8 +72,7 @@ def to_str(self) -> str:
6772

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

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

services/resourcemanager/src/stackit/resourcemanager/models/create_project_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
from stackit.resourcemanager.models.member import Member
@@ -48,14 +49,18 @@ class CreateProjectPayload(BaseModel):
4849
@field_validator("name")
4950
def name_validate_regular_expression(cls, value):
5051
"""Validates the regular expression"""
52+
if not isinstance(value, str):
53+
value = str(value)
54+
5155
if not re.match(r"^[a-zA-ZäüöÄÜÖ0-9]( ?[a-zA-ZäüöÄÜÖß0-9_+&-]){0,39}$", value):
5256
raise ValueError(
5357
r"must validate the regular expression /^[a-zA-ZäüöÄÜÖ0-9]( ?[a-zA-ZäüöÄÜÖß0-9_+&-]){0,39}$/"
5458
)
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/resourcemanager/src/stackit/resourcemanager/models/error_response.py

Lines changed: 4 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 Self
3233

3334

@@ -57,7 +58,8 @@ def time_stamp_change_year_zero_to_one(cls, value):
5758
return value
5859

5960
model_config = ConfigDict(
60-
populate_by_name=True,
61+
validate_by_name=True,
62+
validate_by_alias=True,
6163
validate_assignment=True,
6264
protected_namespaces=(),
6365
)
@@ -68,8 +70,7 @@ def to_str(self) -> str:
6870

6971
def to_json(self) -> str:
7072
"""Returns the JSON representation of the model using alias"""
71-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
72-
return json.dumps(self.to_dict())
73+
return json.dumps(to_jsonable_python(self.to_dict()))
7374

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

services/resourcemanager/src/stackit/resourcemanager/models/folder_response.py

Lines changed: 4 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 Self
2526

2627
from stackit.resourcemanager.models.parent import Parent
@@ -78,7 +79,8 @@ def update_time_change_year_zero_to_one(cls, value):
7879
return value
7980

8081
model_config = ConfigDict(
81-
populate_by_name=True,
82+
validate_by_name=True,
83+
validate_by_alias=True,
8284
validate_assignment=True,
8385
protected_namespaces=(),
8486
)
@@ -89,8 +91,7 @@ def to_str(self) -> str:
8991

9092
def to_json(self) -> str:
9193
"""Returns the JSON representation of the model using alias"""
92-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
93-
return json.dumps(self.to_dict())
94+
return json.dumps(to_jsonable_python(self.to_dict()))
9495

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

services/resourcemanager/src/stackit/resourcemanager/models/get_folder_details_response.py

Lines changed: 4 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 Self
2526

2627
from stackit.resourcemanager.models.parent import Parent
@@ -81,7 +82,8 @@ def update_time_change_year_zero_to_one(cls, value):
8182
return value
8283

8384
model_config = ConfigDict(
84-
populate_by_name=True,
85+
validate_by_name=True,
86+
validate_by_alias=True,
8587
validate_assignment=True,
8688
protected_namespaces=(),
8789
)
@@ -92,8 +94,7 @@ def to_str(self) -> str:
9294

9395
def to_json(self) -> str:
9496
"""Returns the JSON representation of the model using alias"""
95-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
96-
return json.dumps(self.to_dict())
97+
return json.dumps(to_jsonable_python(self.to_dict()))
9798

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

services/resourcemanager/src/stackit/resourcemanager/models/get_project_response.py

Lines changed: 4 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 Self
2526

2627
from stackit.resourcemanager.models.lifecycle_state import LifecycleState
@@ -84,7 +85,8 @@ def update_time_change_year_zero_to_one(cls, value):
8485
return value
8586

8687
model_config = ConfigDict(
87-
populate_by_name=True,
88+
validate_by_name=True,
89+
validate_by_alias=True,
8890
validate_assignment=True,
8991
protected_namespaces=(),
9092
)
@@ -95,8 +97,7 @@ def to_str(self) -> str:
9597

9698
def to_json(self) -> str:
9799
"""Returns the JSON representation of the model using alias"""
98-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
99-
return json.dumps(self.to_dict())
100+
return json.dumps(to_jsonable_python(self.to_dict()))
100101

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

services/resourcemanager/src/stackit/resourcemanager/models/list_folders_response.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, Union
1919

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

2324
from stackit.resourcemanager.models.list_folders_response_items_inner import (
@@ -42,7 +43,8 @@ class ListFoldersResponse(BaseModel):
4243
__properties: ClassVar[List[str]] = ["items", "limit", "offset"]
4344

4445
model_config = ConfigDict(
45-
populate_by_name=True,
46+
validate_by_name=True,
47+
validate_by_alias=True,
4648
validate_assignment=True,
4749
protected_namespaces=(),
4850
)
@@ -53,8 +55,7 @@ def to_str(self) -> str:
5355

5456
def to_json(self) -> str:
5557
"""Returns the JSON representation of the model using alias"""
56-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
57-
return json.dumps(self.to_dict())
58+
return json.dumps(to_jsonable_python(self.to_dict()))
5859

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

0 commit comments

Comments
 (0)