diff --git a/services/ske/oas_commit b/services/ske/oas_commit index 39bada35c..72dcff29c 100644 --- a/services/ske/oas_commit +++ b/services/ske/oas_commit @@ -1 +1 @@ -a35d8f28738a45005b098b66b6debd08a67ab018 +0867dbbb09a8032415dc6debe18bc392bd58ba42 diff --git a/services/ske/src/stackit/ske/api_client.py b/services/ske/src/stackit/ske/api_client.py index 8f8cb852e..280106f0f 100644 --- a/services/ske/src/stackit/ske/api_client.py +++ b/services/ske/src/stackit/ske/api_client.py @@ -66,6 +66,7 @@ class ApiClient: "date": datetime.date, "datetime": datetime.datetime, "decimal": decimal.Decimal, + "UUID": uuid.UUID, "object": object, } _pool = None @@ -265,7 +266,7 @@ def response_deserialize( response_text = None return_data = None try: - if response_type == "bytearray": + if response_type in ("bytearray", "bytes"): return_data = response_data.data elif response_type == "file": return_data = self.__deserialize_file(response_data) @@ -326,25 +327,20 @@ def sanitize_for_serialization(self, obj): return obj.isoformat() elif isinstance(obj, decimal.Decimal): return str(obj) - elif isinstance(obj, dict): - obj_dict = obj + return {key: self.sanitize_for_serialization(val) for key, val in obj.items()} + + # Convert model obj to dict except + # attributes `openapi_types`, `attribute_map` + # and attributes which value is not None. + # Convert attribute name to json key in + # model definition for request. + if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): + obj_dict = obj.to_dict() else: - # Convert model obj to dict except - # attributes `openapi_types`, `attribute_map` - # and attributes which value is not None. - # Convert attribute name to json key in - # model definition for request. - if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): # noqa: B009 - obj_dict = obj.to_dict() - else: - obj_dict = obj.__dict__ - - if isinstance(obj_dict, list): - # 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 - return self.sanitize_for_serialization(obj_dict) + obj_dict = obj.__dict__ - return {key: self.sanitize_for_serialization(val) for key, val in obj_dict.items()} + return self.sanitize_for_serialization(obj_dict) def deserialize(self, response_text: str, response_type: str, content_type: Optional[str]): """Deserializes response into an object. @@ -417,6 +413,8 @@ def __deserialize(self, data, klass): return self.__deserialize_datetime(data) elif klass is decimal.Decimal: return decimal.Decimal(data) + elif klass is uuid.UUID: + return uuid.UUID(data) elif issubclass(klass, Enum): return self.__deserialize_enum(data, klass) else: diff --git a/services/ske/src/stackit/ske/models/access.py b/services/ske/src/stackit/ske/models/access.py index 7e96d233f..93f5ae657 100644 --- a/services/ske/src/stackit/ske/models/access.py +++ b/services/ske/src/stackit/ske/models/access.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict +from pydantic_core import to_jsonable_python from typing_extensions import Self from stackit.ske.models.idp import IDP @@ -32,7 +33,8 @@ class Access(BaseModel): __properties: ClassVar[List[str]] = ["idp"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -43,8 +45,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/acl.py b/services/ske/src/stackit/ske/models/acl.py index 43d97a93a..049ccd449 100644 --- a/services/ske/src/stackit/ske/models/acl.py +++ b/services/ske/src/stackit/ske/models/acl.py @@ -24,6 +24,7 @@ StrictBool, StrictStr, ) +from pydantic_core import to_jsonable_python from typing_extensions import Annotated, Self @@ -39,7 +40,8 @@ class ACL(BaseModel): __properties: ClassVar[List[str]] = ["allowedCidrs", "enabled"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -50,8 +52,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/availability_zone.py b/services/ske/src/stackit/ske/models/availability_zone.py index dad007bc0..4bb7327ab 100644 --- a/services/ske/src/stackit/ske/models/availability_zone.py +++ b/services/ske/src/stackit/ske/models/availability_zone.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -30,7 +31,8 @@ class AvailabilityZone(BaseModel): __properties: ClassVar[List[str]] = ["name"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -41,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/cluster.py b/services/ske/src/stackit/ske/models/cluster.py index 84a32f94c..5bfbbd603 100644 --- a/services/ske/src/stackit/ske/models/cluster.py +++ b/services/ske/src/stackit/ske/models/cluster.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Annotated, Self from stackit.ske.models.access import Access @@ -57,7 +58,8 @@ class Cluster(BaseModel): ] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -68,8 +70,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/cluster_error.py b/services/ske/src/stackit/ske/models/cluster_error.py index c75d8ec84..fca795507 100644 --- a/services/ske/src/stackit/ske/models/cluster_error.py +++ b/services/ske/src/stackit/ske/models/cluster_error.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -34,7 +35,8 @@ class ClusterError(BaseModel): __properties: ClassVar[List[str]] = ["code", "message"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -45,8 +47,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/cluster_status.py b/services/ske/src/stackit/ske/models/cluster_status.py index 8547d63ab..f0029f9fe 100644 --- a/services/ske/src/stackit/ske/models/cluster_status.py +++ b/services/ske/src/stackit/ske/models/cluster_status.py @@ -27,6 +27,7 @@ StrictStr, field_validator, ) +from pydantic_core import to_jsonable_python from typing_extensions import Self from stackit.ske.models.cluster_error import ClusterError @@ -88,7 +89,8 @@ def creation_time_change_year_zero_to_one(cls, value): return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -99,8 +101,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/create_kubeconfig_payload.py b/services/ske/src/stackit/ske/models/create_kubeconfig_payload.py index 3bd0d8956..f396395bb 100644 --- a/services/ske/src/stackit/ske/models/create_kubeconfig_payload.py +++ b/services/ske/src/stackit/ske/models/create_kubeconfig_payload.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -30,7 +31,8 @@ class CreateKubeconfigPayload(BaseModel): __properties: ClassVar[List[str]] = ["expirationSeconds"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -41,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/create_or_update_cluster_payload.py b/services/ske/src/stackit/ske/models/create_or_update_cluster_payload.py index 6e3272251..d6e9e03d4 100644 --- a/services/ske/src/stackit/ske/models/create_or_update_cluster_payload.py +++ b/services/ske/src/stackit/ske/models/create_or_update_cluster_payload.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field +from pydantic_core import to_jsonable_python from typing_extensions import Annotated, Self from stackit.ske.models.access import Access @@ -55,7 +56,8 @@ class CreateOrUpdateClusterPayload(BaseModel): ] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -66,8 +68,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/credentials_rotation_state.py b/services/ske/src/stackit/ske/models/credentials_rotation_state.py index 0af820510..76ebe5f9f 100644 --- a/services/ske/src/stackit/ske/models/credentials_rotation_state.py +++ b/services/ske/src/stackit/ske/models/credentials_rotation_state.py @@ -20,6 +20,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -77,7 +78,8 @@ def phase_validate_enum(cls, value): return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -88,8 +90,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/cri.py b/services/ske/src/stackit/ske/models/cri.py index 9a0c0e94e..6aa0dea95 100644 --- a/services/ske/src/stackit/ske/models/cri.py +++ b/services/ske/src/stackit/ske/models/cri.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, StrictStr, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -40,7 +41,8 @@ def name_validate_enum(cls, value): return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -51,8 +53,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/dns.py b/services/ske/src/stackit/ske/models/dns.py index b7348ded8..3643b2fad 100644 --- a/services/ske/src/stackit/ske/models/dns.py +++ b/services/ske/src/stackit/ske/models/dns.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictBool +from pydantic_core import to_jsonable_python from typing_extensions import Annotated, Self @@ -33,7 +34,8 @@ class DNS(BaseModel): __properties: ClassVar[List[str]] = ["enabled", "zones"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -44,8 +46,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/expiration_status.py b/services/ske/src/stackit/ske/models/expiration_status.py index c64ab3e22..af42bc701 100644 --- a/services/ske/src/stackit/ske/models/expiration_status.py +++ b/services/ske/src/stackit/ske/models/expiration_status.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict +from pydantic_core import to_jsonable_python from typing_extensions import Self from stackit.ske.models.expiration_status_kubernetes import ExpirationStatusKubernetes @@ -34,7 +35,8 @@ class ExpirationStatus(BaseModel): __properties: ClassVar[List[str]] = ["kubernetes", "nodepools"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -45,8 +47,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/expiration_status_kubernetes.py b/services/ske/src/stackit/ske/models/expiration_status_kubernetes.py index 1710fa07e..ca62a5340 100644 --- a/services/ske/src/stackit/ske/models/expiration_status_kubernetes.py +++ b/services/ske/src/stackit/ske/models/expiration_status_kubernetes.py @@ -20,6 +20,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -46,7 +47,8 @@ def expiration_date_change_year_zero_to_one(cls, value): return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -57,8 +59,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/expiration_status_nodepool.py b/services/ske/src/stackit/ske/models/expiration_status_nodepool.py index 10190f203..5cef32ee9 100644 --- a/services/ske/src/stackit/ske/models/expiration_status_nodepool.py +++ b/services/ske/src/stackit/ske/models/expiration_status_nodepool.py @@ -20,6 +20,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -70,7 +71,8 @@ def os_expiration_date_change_year_zero_to_one(cls, value): return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -81,8 +83,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/extension.py b/services/ske/src/stackit/ske/models/extension.py index a22771384..7f84c926b 100644 --- a/services/ske/src/stackit/ske/models/extension.py +++ b/services/ske/src/stackit/ske/models/extension.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict +from pydantic_core import to_jsonable_python from typing_extensions import Self from stackit.ske.models.acl import ACL @@ -36,7 +37,8 @@ class Extension(BaseModel): __properties: ClassVar[List[str]] = ["acl", "dns", "observability"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -47,8 +49,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/hibernation.py b/services/ske/src/stackit/ske/models/hibernation.py index 8adfc480e..14e21d303 100644 --- a/services/ske/src/stackit/ske/models/hibernation.py +++ b/services/ske/src/stackit/ske/models/hibernation.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict +from pydantic_core import to_jsonable_python from typing_extensions import Self from stackit.ske.models.hibernation_schedule import HibernationSchedule @@ -32,7 +33,8 @@ class Hibernation(BaseModel): __properties: ClassVar[List[str]] = ["schedules"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -43,8 +45,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/hibernation_schedule.py b/services/ske/src/stackit/ske/models/hibernation_schedule.py index bbb20b262..de6983af2 100644 --- a/services/ske/src/stackit/ske/models/hibernation_schedule.py +++ b/services/ske/src/stackit/ske/models/hibernation_schedule.py @@ -19,6 +19,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Annotated, Self @@ -35,6 +36,9 @@ class HibernationSchedule(BaseModel): @field_validator("end") def end_validate_regular_expression(cls, value): """Validates the regular expression""" + if not isinstance(value, str): + value = str(value) + if not re.match( r"(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\\d+(ns|us|µs|ms|s|m|h))+)|((((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7})", value, @@ -47,6 +51,9 @@ def end_validate_regular_expression(cls, value): @field_validator("start") def start_validate_regular_expression(cls, value): """Validates the regular expression""" + if not isinstance(value, str): + value = str(value) + if not re.match( r"(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\\d+(ns|us|µs|ms|s|m|h))+)|((((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7})", value, @@ -57,7 +64,8 @@ def start_validate_regular_expression(cls, value): return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -68,8 +76,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/idp.py b/services/ske/src/stackit/ske/models/idp.py index 296dab7e1..9feb120de 100644 --- a/services/ske/src/stackit/ske/models/idp.py +++ b/services/ske/src/stackit/ske/models/idp.py @@ -24,6 +24,7 @@ StrictBool, StrictStr, ) +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -37,7 +38,8 @@ class IDP(BaseModel): __properties: ClassVar[List[str]] = ["enabled", "type"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -48,8 +50,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/idp_kubeconfig.py b/services/ske/src/stackit/ske/models/idp_kubeconfig.py index 8714cfbda..c1895903a 100644 --- a/services/ske/src/stackit/ske/models/idp_kubeconfig.py +++ b/services/ske/src/stackit/ske/models/idp_kubeconfig.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -30,7 +31,8 @@ class IDPKubeconfig(BaseModel): __properties: ClassVar[List[str]] = ["kubeconfig"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -41,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/image.py b/services/ske/src/stackit/ske/models/image.py index c230ee890..35b6be469 100644 --- a/services/ske/src/stackit/ske/models/image.py +++ b/services/ske/src/stackit/ske/models/image.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -31,7 +32,8 @@ class Image(BaseModel): __properties: ClassVar[List[str]] = ["name", "version"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -42,8 +44,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/kubeconfig.py b/services/ske/src/stackit/ske/models/kubeconfig.py index 6d984c8cc..4f0a6fcd3 100644 --- a/services/ske/src/stackit/ske/models/kubeconfig.py +++ b/services/ske/src/stackit/ske/models/kubeconfig.py @@ -20,6 +20,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -46,7 +47,8 @@ def expiration_timestamp_change_year_zero_to_one(cls, value): return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -57,8 +59,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/kubernetes.py b/services/ske/src/stackit/ske/models/kubernetes.py index 8ccf7be63..1bd7547d3 100644 --- a/services/ske/src/stackit/ske/models/kubernetes.py +++ b/services/ske/src/stackit/ske/models/kubernetes.py @@ -19,6 +19,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Annotated, Self @@ -33,12 +34,16 @@ class Kubernetes(BaseModel): @field_validator("version") def version_validate_regular_expression(cls, value): """Validates the regular expression""" + if not isinstance(value, str): + value = str(value) + if not re.match(r"^\d+\.\d+\.\d+$", value): raise ValueError(r"must validate the regular expression /^\d+\.\d+\.\d+$/") return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -49,8 +54,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/kubernetes_version.py b/services/ske/src/stackit/ske/models/kubernetes_version.py index b454121ca..09eb90630 100644 --- a/services/ske/src/stackit/ske/models/kubernetes_version.py +++ b/services/ske/src/stackit/ske/models/kubernetes_version.py @@ -20,6 +20,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Annotated, Self @@ -53,12 +54,16 @@ def version_validate_regular_expression(cls, value): if value is None: return value + if not isinstance(value, str): + value = str(value) + if not re.match(r"^\d+\.\d+\.\d+$", value): raise ValueError(r"must validate the regular expression /^\d+\.\d+\.\d+$/") return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -69,8 +74,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/list_clusters_response.py b/services/ske/src/stackit/ske/models/list_clusters_response.py index 428e1b0ed..9568fb975 100644 --- a/services/ske/src/stackit/ske/models/list_clusters_response.py +++ b/services/ske/src/stackit/ske/models/list_clusters_response.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict +from pydantic_core import to_jsonable_python from typing_extensions import Self from stackit.ske.models.cluster import Cluster @@ -32,7 +33,8 @@ class ListClustersResponse(BaseModel): __properties: ClassVar[List[str]] = ["items"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -43,8 +45,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/login_kubeconfig.py b/services/ske/src/stackit/ske/models/login_kubeconfig.py index e28b75909..9804cd5fa 100644 --- a/services/ske/src/stackit/ske/models/login_kubeconfig.py +++ b/services/ske/src/stackit/ske/models/login_kubeconfig.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -30,7 +31,8 @@ class LoginKubeconfig(BaseModel): __properties: ClassVar[List[str]] = ["kubeconfig"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -41,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/machine.py b/services/ske/src/stackit/ske/models/machine.py index f4c8cef0f..1269f8e5a 100644 --- a/services/ske/src/stackit/ske/models/machine.py +++ b/services/ske/src/stackit/ske/models/machine.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Self from stackit.ske.models.image import Image @@ -35,7 +36,8 @@ class Machine(BaseModel): __properties: ClassVar[List[str]] = ["image", "type"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -46,8 +48,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/machine_image.py b/services/ske/src/stackit/ske/models/machine_image.py index 082d9b4a9..e16f0adee 100644 --- a/services/ske/src/stackit/ske/models/machine_image.py +++ b/services/ske/src/stackit/ske/models/machine_image.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Self from stackit.ske.models.machine_image_version import MachineImageVersion @@ -33,7 +34,8 @@ class MachineImage(BaseModel): __properties: ClassVar[List[str]] = ["name", "versions"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -44,8 +46,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/machine_image_version.py b/services/ske/src/stackit/ske/models/machine_image_version.py index 489c28ab0..1396fa772 100644 --- a/services/ske/src/stackit/ske/models/machine_image_version.py +++ b/services/ske/src/stackit/ske/models/machine_image_version.py @@ -20,6 +20,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Annotated, Self from stackit.ske.models.cri import CRI @@ -55,12 +56,16 @@ def version_validate_regular_expression(cls, value): if value is None: return value + if not isinstance(value, str): + value = str(value) + if not re.match(r"^\d+\.\d+\.\d+$", value): raise ValueError(r"must validate the regular expression /^\d+\.\d+\.\d+$/") return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -71,8 +76,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/machine_type.py b/services/ske/src/stackit/ske/models/machine_type.py index 7dfcf7ccc..e4b4db2af 100644 --- a/services/ske/src/stackit/ske/models/machine_type.py +++ b/services/ske/src/stackit/ske/models/machine_type.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -34,7 +35,8 @@ class MachineType(BaseModel): __properties: ClassVar[List[str]] = ["architecture", "cpu", "gpu", "memory", "name"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -45,8 +47,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/maintenance.py b/services/ske/src/stackit/ske/models/maintenance.py index 31e2d0ee8..dc2d89611 100644 --- a/services/ske/src/stackit/ske/models/maintenance.py +++ b/services/ske/src/stackit/ske/models/maintenance.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field +from pydantic_core import to_jsonable_python from typing_extensions import Self from stackit.ske.models.maintenance_auto_update import MaintenanceAutoUpdate @@ -34,7 +35,8 @@ class Maintenance(BaseModel): __properties: ClassVar[List[str]] = ["autoUpdate", "timeWindow"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -45,8 +47,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/maintenance_auto_update.py b/services/ske/src/stackit/ske/models/maintenance_auto_update.py index 32277d6de..75a4efa34 100644 --- a/services/ske/src/stackit/ske/models/maintenance_auto_update.py +++ b/services/ske/src/stackit/ske/models/maintenance_auto_update.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictBool +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -31,7 +32,8 @@ class MaintenanceAutoUpdate(BaseModel): __properties: ClassVar[List[str]] = ["kubernetesVersion", "machineImageVersion"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -42,8 +44,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/network.py b/services/ske/src/stackit/ske/models/network.py index 3a1915e12..a9f0ee9a8 100644 --- a/services/ske/src/stackit/ske/models/network.py +++ b/services/ske/src/stackit/ske/models/network.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Self from stackit.ske.models.v2_control_plane_network import V2ControlPlaneNetwork @@ -33,7 +34,8 @@ class Network(BaseModel): __properties: ClassVar[List[str]] = ["controlPlane", "id"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -44,8 +46,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/nodepool.py b/services/ske/src/stackit/ske/models/nodepool.py index 1ff8e7e54..c181559c7 100644 --- a/services/ske/src/stackit/ske/models/nodepool.py +++ b/services/ske/src/stackit/ske/models/nodepool.py @@ -25,6 +25,7 @@ StrictInt, StrictStr, ) +from pydantic_core import to_jsonable_python from typing_extensions import Annotated, Self from stackit.ske.models.cri import CRI @@ -75,7 +76,8 @@ class Nodepool(BaseModel): ] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -86,8 +88,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/nodepool_kubernetes.py b/services/ske/src/stackit/ske/models/nodepool_kubernetes.py index fdac8139b..10d9cd2fa 100644 --- a/services/ske/src/stackit/ske/models/nodepool_kubernetes.py +++ b/services/ske/src/stackit/ske/models/nodepool_kubernetes.py @@ -19,6 +19,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Annotated, Self @@ -39,12 +40,16 @@ def version_validate_regular_expression(cls, value): if value is None: return value + if not isinstance(value, str): + value = str(value) + if not re.match(r"^\d+\.\d+\.\d+$", value): raise ValueError(r"must validate the regular expression /^\d+\.\d+\.\d+$/") return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -55,8 +60,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/observability.py b/services/ske/src/stackit/ske/models/observability.py index cef11e4bc..1e47a74e0 100644 --- a/services/ske/src/stackit/ske/models/observability.py +++ b/services/ske/src/stackit/ske/models/observability.py @@ -24,6 +24,7 @@ StrictBool, StrictStr, ) +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -39,7 +40,8 @@ class Observability(BaseModel): __properties: ClassVar[List[str]] = ["enabled", "instanceId"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -50,8 +52,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/provider_options.py b/services/ske/src/stackit/ske/models/provider_options.py index 125fdeafc..a678da171 100644 --- a/services/ske/src/stackit/ske/models/provider_options.py +++ b/services/ske/src/stackit/ske/models/provider_options.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field +from pydantic_core import to_jsonable_python from typing_extensions import Self from stackit.ske.models.availability_zone import AvailabilityZone @@ -46,7 +47,8 @@ class ProviderOptions(BaseModel): ] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -57,8 +59,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/runtime_error.py b/services/ske/src/stackit/ske/models/runtime_error.py index 7c09f9a9f..2c2f25e1a 100644 --- a/services/ske/src/stackit/ske/models/runtime_error.py +++ b/services/ske/src/stackit/ske/models/runtime_error.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -61,7 +62,8 @@ def code_validate_enum(cls, value): return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -72,8 +74,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/taint.py b/services/ske/src/stackit/ske/models/taint.py index 70b85c88d..1a851b821 100644 --- a/services/ske/src/stackit/ske/models/taint.py +++ b/services/ske/src/stackit/ske/models/taint.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, StrictStr, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -39,7 +40,8 @@ def effect_validate_enum(cls, value): return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -50,8 +52,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/time_window.py b/services/ske/src/stackit/ske/models/time_window.py index a0d93dba3..fc84cb973 100644 --- a/services/ske/src/stackit/ske/models/time_window.py +++ b/services/ske/src/stackit/ske/models/time_window.py @@ -20,6 +20,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -59,7 +60,8 @@ def start_change_year_zero_to_one(cls, value): return value model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -70,8 +72,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/v2_control_plane_network.py b/services/ske/src/stackit/ske/models/v2_control_plane_network.py index d36932b10..8652d1b99 100644 --- a/services/ske/src/stackit/ske/models/v2_control_plane_network.py +++ b/services/ske/src/stackit/ske/models/v2_control_plane_network.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field +from pydantic_core import to_jsonable_python from typing_extensions import Self from stackit.ske.models.access_scope import AccessScope @@ -32,7 +33,8 @@ class V2ControlPlaneNetwork(BaseModel): __properties: ClassVar[List[str]] = ["accessScope"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -43,8 +45,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/volume.py b/services/ske/src/stackit/ske/models/volume.py index 26ce855ac..d5c7ffb59 100644 --- a/services/ske/src/stackit/ske/models/volume.py +++ b/services/ske/src/stackit/ske/models/volume.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Annotated, Self @@ -34,7 +35,8 @@ class Volume(BaseModel): __properties: ClassVar[List[str]] = ["size", "type"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -45,8 +47,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: diff --git a/services/ske/src/stackit/ske/models/volume_type.py b/services/ske/src/stackit/ske/models/volume_type.py index 5f501f30b..e8c6e2ade 100644 --- a/services/ske/src/stackit/ske/models/volume_type.py +++ b/services/ske/src/stackit/ske/models/volume_type.py @@ -18,6 +18,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, StrictStr +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -30,7 +31,8 @@ class VolumeType(BaseModel): __properties: ClassVar[List[str]] = ["name"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -41,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return json.dumps(to_jsonable_python(self.to_dict())) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: