Skip to content

Commit 8c26d85

Browse files
Generate cost
1 parent 875e273 commit 8c26d85

12 files changed

Lines changed: 56 additions & 48 deletions

services/cost/oas_commit

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

services/cost/src/stackit/cost/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/cost/src/stackit/cost/models/auth_error_response.py

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

2222
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
23+
from pydantic_core import to_jsonable_python
2324
from typing_extensions import Self
2425

2526

@@ -49,7 +50,8 @@ def time_stamp_change_year_zero_to_one(cls, value):
4950
return value
5051

5152
model_config = ConfigDict(
52-
populate_by_name=True,
53+
validate_by_name=True,
54+
validate_by_alias=True,
5355
validate_assignment=True,
5456
protected_namespaces=(),
5557
)
@@ -60,8 +62,7 @@ def to_str(self) -> str:
6062

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

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

services/cost/src/stackit/cost/models/detailed_service_cost.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
StrictFloat,
2525
StrictInt,
2626
)
27+
from pydantic_core import to_jsonable_python
2728
from typing_extensions import Annotated, Self
2829

2930
from stackit.cost.models.report_data import ReportData
@@ -70,7 +71,8 @@ class DetailedServiceCost(BaseModel):
7071
]
7172

7273
model_config = ConfigDict(
73-
populate_by_name=True,
74+
validate_by_name=True,
75+
validate_by_alias=True,
7476
validate_assignment=True,
7577
protected_namespaces=(),
7678
)
@@ -81,8 +83,7 @@ def to_str(self) -> str:
8183

8284
def to_json(self) -> str:
8385
"""Returns the JSON representation of the model using alias"""
84-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
85-
return json.dumps(self.to_dict())
86+
return json.dumps(to_jsonable_python(self.to_dict()))
8687

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

services/cost/src/stackit/cost/models/error_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
1919

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

2324

@@ -30,7 +31,8 @@ class ErrorResponse(BaseModel):
3031
__properties: ClassVar[List[str]] = ["msg"]
3132

3233
model_config = ConfigDict(
33-
populate_by_name=True,
34+
validate_by_name=True,
35+
validate_by_alias=True,
3436
validate_assignment=True,
3537
protected_namespaces=(),
3638
)
@@ -41,8 +43,7 @@ def to_str(self) -> str:
4143

4244
def to_json(self) -> str:
4345
"""Returns the JSON representation of the model using alias"""
44-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
45-
return json.dumps(self.to_dict())
46+
return json.dumps(to_jsonable_python(self.to_dict()))
4647

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

services/cost/src/stackit/cost/models/project_cost_with_detailed_services.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
StrictInt,
2727
StrictStr,
2828
)
29+
from pydantic_core import to_jsonable_python
2930
from typing_extensions import Self
3031

3132
from stackit.cost.models.detailed_service_cost import DetailedServiceCost
@@ -61,7 +62,8 @@ class ProjectCostWithDetailedServices(BaseModel):
6162
]
6263

6364
model_config = ConfigDict(
64-
populate_by_name=True,
65+
validate_by_name=True,
66+
validate_by_alias=True,
6567
validate_assignment=True,
6668
protected_namespaces=(),
6769
)
@@ -72,8 +74,7 @@ def to_str(self) -> str:
7274

7375
def to_json(self) -> str:
7476
"""Returns the JSON representation of the model using alias"""
75-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
76-
return json.dumps(self.to_dict())
77+
return json.dumps(to_jsonable_python(self.to_dict()))
7778

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

services/cost/src/stackit/cost/models/project_cost_with_reports.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
StrictInt,
2727
StrictStr,
2828
)
29+
from pydantic_core import to_jsonable_python
2930
from typing_extensions import Self
3031

3132
from stackit.cost.models.report_data import ReportData
@@ -62,7 +63,8 @@ class ProjectCostWithReports(BaseModel):
6263
]
6364

6465
model_config = ConfigDict(
65-
populate_by_name=True,
66+
validate_by_name=True,
67+
validate_by_alias=True,
6668
validate_assignment=True,
6769
protected_namespaces=(),
6870
)
@@ -73,8 +75,7 @@ def to_str(self) -> str:
7375

7476
def to_json(self) -> str:
7577
"""Returns the JSON representation of the model using alias"""
76-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
77-
return json.dumps(self.to_dict())
78+
return json.dumps(to_jsonable_python(self.to_dict()))
7879

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

services/cost/src/stackit/cost/models/project_cost_with_summarized_services.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
StrictInt,
2727
StrictStr,
2828
)
29+
from pydantic_core import to_jsonable_python
2930
from typing_extensions import Self
3031

3132
from stackit.cost.models.summarized_service_cost import SummarizedServiceCost
@@ -58,7 +59,8 @@ class ProjectCostWithSummarizedServices(BaseModel):
5859
]
5960

6061
model_config = ConfigDict(
61-
populate_by_name=True,
62+
validate_by_name=True,
63+
validate_by_alias=True,
6264
validate_assignment=True,
6365
protected_namespaces=(),
6466
)
@@ -69,8 +71,7 @@ def to_str(self) -> str:
6971

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

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

services/cost/src/stackit/cost/models/report_data.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
StrictFloat,
2525
StrictInt,
2626
)
27+
from pydantic_core import to_jsonable_python
2728
from typing_extensions import Self
2829

2930
from stackit.cost.models.report_data_time_period import ReportDataTimePeriod
@@ -41,7 +42,8 @@ class ReportData(BaseModel):
4142
__properties: ClassVar[List[str]] = ["charge", "discount", "quantity", "timePeriod"]
4243

4344
model_config = ConfigDict(
44-
populate_by_name=True,
45+
validate_by_name=True,
46+
validate_by_alias=True,
4547
validate_assignment=True,
4648
protected_namespaces=(),
4749
)
@@ -52,8 +54,7 @@ def to_str(self) -> str:
5254

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

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

services/cost/src/stackit/cost/models/report_data_time_period.py

Lines changed: 4 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
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Self
2324

2425

@@ -32,7 +33,8 @@ class ReportDataTimePeriod(BaseModel):
3233
__properties: ClassVar[List[str]] = ["end", "start"]
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]:

0 commit comments

Comments
 (0)