diff --git a/services/runcommand/oas_commit b/services/runcommand/oas_commit index e3713dde3..72dcff29c 100644 --- a/services/runcommand/oas_commit +++ b/services/runcommand/oas_commit @@ -1 +1 @@ -0e64886dd0847341800d7191ed193b75413be998 +0867dbbb09a8032415dc6debe18bc392bd58ba42 diff --git a/services/runcommand/src/stackit/runcommand/api_client.py b/services/runcommand/src/stackit/runcommand/api_client.py index 3266ae4c4..184d053a4 100644 --- a/services/runcommand/src/stackit/runcommand/api_client.py +++ b/services/runcommand/src/stackit/runcommand/api_client.py @@ -67,6 +67,7 @@ class ApiClient: "date": datetime.date, "datetime": datetime.datetime, "decimal": decimal.Decimal, + "UUID": uuid.UUID, "object": object, } _pool = None @@ -266,7 +267,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) @@ -327,25 +328,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. @@ -418,6 +414,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/runcommand/src/stackit/runcommand/models/command_details.py b/services/runcommand/src/stackit/runcommand/models/command_details.py index cf6b325c2..9ea71901e 100644 --- a/services/runcommand/src/stackit/runcommand/models/command_details.py +++ b/services/runcommand/src/stackit/runcommand/models/command_details.py @@ -19,6 +19,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -59,7 +60,8 @@ def status_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=(), ) @@ -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/runcommand/src/stackit/runcommand/models/command_template.py b/services/runcommand/src/stackit/runcommand/models/command_template.py index b02cd1cd8..22c70f623 100644 --- a/services/runcommand/src/stackit/runcommand/models/command_template.py +++ b/services/runcommand/src/stackit/runcommand/models/command_template.py @@ -19,6 +19,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 @@ -33,7 +34,8 @@ class CommandTemplate(BaseModel): __properties: ClassVar[List[str]] = ["name", "osType", "title"] 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/runcommand/src/stackit/runcommand/models/command_template_response.py b/services/runcommand/src/stackit/runcommand/models/command_template_response.py index 7e8310979..bcb6ec2db 100644 --- a/services/runcommand/src/stackit/runcommand/models/command_template_response.py +++ b/services/runcommand/src/stackit/runcommand/models/command_template_response.py @@ -19,6 +19,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.runcommand.models.command_template import CommandTemplate @@ -33,7 +34,8 @@ class CommandTemplateResponse(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=(), ) @@ -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/runcommand/src/stackit/runcommand/models/command_template_schema.py b/services/runcommand/src/stackit/runcommand/models/command_template_schema.py index 58b4a644f..7343ddf02 100644 --- a/services/runcommand/src/stackit/runcommand/models/command_template_schema.py +++ b/services/runcommand/src/stackit/runcommand/models/command_template_schema.py @@ -19,6 +19,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.runcommand.models.parameters_schema import ParametersSchema @@ -37,7 +38,8 @@ class CommandTemplateSchema(BaseModel): __properties: ClassVar[List[str]] = ["description", "name", "osType", "parametersSchema", "title"] 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/runcommand/src/stackit/runcommand/models/commands.py b/services/runcommand/src/stackit/runcommand/models/commands.py index cddd29b98..629ff1396 100644 --- a/services/runcommand/src/stackit/runcommand/models/commands.py +++ b/services/runcommand/src/stackit/runcommand/models/commands.py @@ -19,6 +19,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -53,7 +54,8 @@ def status_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=(), ) @@ -64,8 +66,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/runcommand/src/stackit/runcommand/models/create_command_payload.py b/services/runcommand/src/stackit/runcommand/models/create_command_payload.py index 19875b7ee..3b5e62cc6 100644 --- a/services/runcommand/src/stackit/runcommand/models/create_command_payload.py +++ b/services/runcommand/src/stackit/runcommand/models/create_command_payload.py @@ -19,6 +19,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 @@ -32,7 +33,8 @@ class CreateCommandPayload(BaseModel): __properties: ClassVar[List[str]] = ["commandTemplateName", "parameters"] 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/runcommand/src/stackit/runcommand/models/error_response.py b/services/runcommand/src/stackit/runcommand/models/error_response.py index 14b357657..011e38fe3 100644 --- a/services/runcommand/src/stackit/runcommand/models/error_response.py +++ b/services/runcommand/src/stackit/runcommand/models/error_response.py @@ -19,6 +19,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 ErrorResponse(BaseModel): __properties: ClassVar[List[str]] = ["message", "status"] 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/runcommand/src/stackit/runcommand/models/get_commands_response.py b/services/runcommand/src/stackit/runcommand/models/get_commands_response.py index 6b71cf998..6806ecb0e 100644 --- a/services/runcommand/src/stackit/runcommand/models/get_commands_response.py +++ b/services/runcommand/src/stackit/runcommand/models/get_commands_response.py @@ -19,6 +19,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.runcommand.models.commands import Commands @@ -33,7 +34,8 @@ class GetCommandsResponse(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=(), ) @@ -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/runcommand/src/stackit/runcommand/models/model_field.py b/services/runcommand/src/stackit/runcommand/models/model_field.py index fd9065390..9303e176f 100644 --- a/services/runcommand/src/stackit/runcommand/models/model_field.py +++ b/services/runcommand/src/stackit/runcommand/models/model_field.py @@ -26,6 +26,7 @@ StrictInt, StrictStr, ) +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -44,7 +45,8 @@ class ModelField(BaseModel): __properties: ClassVar[List[str]] = ["default", "description", "maxLen", "minLen", "readOnly", "title", "type"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -55,8 +57,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/runcommand/src/stackit/runcommand/models/new_command_response.py b/services/runcommand/src/stackit/runcommand/models/new_command_response.py index fa5b7f7c7..dae63ab81 100644 --- a/services/runcommand/src/stackit/runcommand/models/new_command_response.py +++ b/services/runcommand/src/stackit/runcommand/models/new_command_response.py @@ -19,6 +19,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Set from pydantic import BaseModel, ConfigDict, StrictInt +from pydantic_core import to_jsonable_python from typing_extensions import Self @@ -31,7 +32,8 @@ class NewCommandResponse(BaseModel): __properties: ClassVar[List[str]] = ["id"] 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/runcommand/src/stackit/runcommand/models/parameters_schema.py b/services/runcommand/src/stackit/runcommand/models/parameters_schema.py index cffe6a4bf..d44f8899b 100644 --- a/services/runcommand/src/stackit/runcommand/models/parameters_schema.py +++ b/services/runcommand/src/stackit/runcommand/models/parameters_schema.py @@ -19,6 +19,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.runcommand.models.properties import Properties @@ -33,7 +34,8 @@ class ParametersSchema(BaseModel): __properties: ClassVar[List[str]] = ["properties"] 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/runcommand/src/stackit/runcommand/models/properties.py b/services/runcommand/src/stackit/runcommand/models/properties.py index e00cd995b..0b1ec92f8 100644 --- a/services/runcommand/src/stackit/runcommand/models/properties.py +++ b/services/runcommand/src/stackit/runcommand/models/properties.py @@ -19,6 +19,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.runcommand.models.model_field import ModelField @@ -38,7 +39,8 @@ class Properties(BaseModel): __properties: ClassVar[List[str]] = ["ConfirmPassword", "Password", "Script", "Username", "required", "type"] model_config = ConfigDict( - populate_by_name=True, + validate_by_name=True, + validate_by_alias=True, validate_assignment=True, protected_namespaces=(), ) @@ -49,8 +51,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]: