Skip to content

Commit 1484126

Browse files
Generate telemetryrouter
1 parent 875e273 commit 1484126

26 files changed

Lines changed: 151 additions & 90 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a896a71ffc1c1152f63b40a0194ac461ce179d6c
1+
0867dbbb09a8032415dc6debe18bc392bd58ba42

services/telemetryrouter/src/stackit/telemetryrouter/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/telemetryrouter/src/stackit/telemetryrouter/models/access_token_base_request.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

@@ -42,12 +43,16 @@ class AccessTokenBaseRequest(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-Z0-9][a-zA-Z0-9 \-]*$", value):
4650
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9][a-zA-Z0-9 \-]*$/")
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/telemetryrouter/src/stackit/telemetryrouter/models/access_token_base_response.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

@@ -48,6 +49,9 @@ class AccessTokenBaseResponse(BaseModel):
4849
@field_validator("display_name")
4950
def display_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-Z0-9][a-zA-Z0-9 ]*$", value):
5256
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9][a-zA-Z0-9 ]*$/")
5357
return value
@@ -73,7 +77,8 @@ def status_validate_enum(cls, value):
7377
return value
7478

7579
model_config = ConfigDict(
76-
populate_by_name=True,
80+
validate_by_name=True,
81+
validate_by_alias=True,
7782
validate_assignment=True,
7883
protected_namespaces=(),
7984
)
@@ -84,8 +89,7 @@ def to_str(self) -> str:
8489

8590
def to_json(self) -> str:
8691
"""Returns the JSON representation of the model using alias"""
87-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
88-
return json.dumps(self.to_dict())
92+
return json.dumps(to_jsonable_python(self.to_dict()))
8993

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

services/telemetryrouter/src/stackit/telemetryrouter/models/config_filter.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, Field
21+
from pydantic_core import to_jsonable_python
2122
from typing_extensions import Annotated, Self
2223

2324
from stackit.telemetryrouter.models.config_filter_attributes import (
@@ -34,7 +35,8 @@ class ConfigFilter(BaseModel):
3435
__properties: ClassVar[List[str]] = ["attributes"]
3536

3637
model_config = ConfigDict(
37-
populate_by_name=True,
38+
validate_by_name=True,
39+
validate_by_alias=True,
3840
validate_assignment=True,
3941
protected_namespaces=(),
4042
)
@@ -45,8 +47,7 @@ def to_str(self) -> str:
4547

4648
def to_json(self) -> str:
4749
"""Returns the JSON representation of the model using alias"""
48-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
49-
return json.dumps(self.to_dict())
50+
return json.dumps(to_jsonable_python(self.to_dict()))
5051

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

services/telemetryrouter/src/stackit/telemetryrouter/models/config_filter_attributes.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, Field
21+
from pydantic_core import to_jsonable_python
2122
from typing_extensions import Annotated, Self
2223

2324
from stackit.telemetryrouter.models.config_filter_level import ConfigFilterLevel
@@ -38,7 +39,8 @@ class ConfigFilterAttributes(BaseModel):
3839
__properties: ClassVar[List[str]] = ["key", "level", "matcher", "values"]
3940

4041
model_config = ConfigDict(
41-
populate_by_name=True,
42+
validate_by_name=True,
43+
validate_by_alias=True,
4244
validate_assignment=True,
4345
protected_namespaces=(),
4446
)
@@ -49,8 +51,7 @@ def to_str(self) -> str:
4951

5052
def to_json(self) -> str:
5153
"""Returns the JSON representation of the model using alias"""
52-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
53-
return json.dumps(self.to_dict())
54+
return json.dumps(to_jsonable_python(self.to_dict()))
5455

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

services/telemetryrouter/src/stackit/telemetryrouter/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, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425

@@ -42,12 +43,16 @@ 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-Z0-9][a-zA-Z0-9 \-]*$", value):
4650
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9][a-zA-Z0-9 \-]*$/")
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/telemetryrouter/src/stackit/telemetryrouter/models/create_access_token_response.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

@@ -57,6 +58,9 @@ class CreateAccessTokenResponse(BaseModel):
5758
@field_validator("display_name")
5859
def display_name_validate_regular_expression(cls, value):
5960
"""Validates the regular expression"""
61+
if not isinstance(value, str):
62+
value = str(value)
63+
6064
if not re.match(r"^[a-zA-Z0-9][a-zA-Z0-9 ]*$", value):
6165
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9][a-zA-Z0-9 ]*$/")
6266
return value
@@ -82,7 +86,8 @@ def status_validate_enum(cls, value):
8286
return value
8387

8488
model_config = ConfigDict(
85-
populate_by_name=True,
89+
validate_by_name=True,
90+
validate_by_alias=True,
8691
validate_assignment=True,
8792
protected_namespaces=(),
8893
)
@@ -93,8 +98,7 @@ def to_str(self) -> str:
9398

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

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

services/telemetryrouter/src/stackit/telemetryrouter/models/create_destination_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
from stackit.telemetryrouter.models.destination_config import DestinationConfig
@@ -42,12 +43,16 @@ class CreateDestinationPayload(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-Z0-9][a-zA-Z0-9 \-]*$", value):
4650
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9][a-zA-Z0-9 \-]*$/")
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/telemetryrouter/src/stackit/telemetryrouter/models/create_telemetry_router_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
from stackit.telemetryrouter.models.config_filter import ConfigFilter
@@ -42,12 +43,16 @@ class CreateTelemetryRouterPayload(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-Z0-9][a-zA-Z0-9 \-]*$", value):
4650
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9][a-zA-Z0-9 \-]*$/")
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]:

0 commit comments

Comments
 (0)