add openapi-python-client generator + client
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
import json
|
||||
from collections.abc import Mapping
|
||||
from typing import TYPE_CHECKING, Any, TypeVar, Union
|
||||
|
||||
from attrs import define as _attrs_define
|
||||
from attrs import field as _attrs_field
|
||||
|
||||
from .. import types
|
||||
from ..types import UNSET, Unset
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..models.add_to_basket_node_extra_info_group import AddToBasketNodeExtraInfoGroup
|
||||
|
||||
|
||||
T = TypeVar("T", bound="SelectedNodeCreation")
|
||||
|
||||
|
||||
@_attrs_define
|
||||
class SelectedNodeCreation:
|
||||
"""A serializer used specifically in the add-to-basket process. This serializer allows specifying all properties needed
|
||||
to add one item to the basket, including any extra info (groups).
|
||||
This serializer only needs the pks of Nodes, not of NodeConfigurations, as we can determine them directly in this
|
||||
direction.
|
||||
|
||||
Attributes:
|
||||
node (int):
|
||||
node_extra_info_groups (Union[Unset, list['AddToBasketNodeExtraInfoGroup']]):
|
||||
children (Union[Unset, list['SelectedNodeCreation']]):
|
||||
"""
|
||||
|
||||
node: int
|
||||
node_extra_info_groups: Union[Unset, list["AddToBasketNodeExtraInfoGroup"]] = UNSET
|
||||
children: Union[Unset, list["SelectedNodeCreation"]] = UNSET
|
||||
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
node = self.node
|
||||
|
||||
node_extra_info_groups: Union[Unset, list[dict[str, Any]]] = UNSET
|
||||
if not isinstance(self.node_extra_info_groups, Unset):
|
||||
node_extra_info_groups = []
|
||||
for node_extra_info_groups_item_data in self.node_extra_info_groups:
|
||||
node_extra_info_groups_item = node_extra_info_groups_item_data.to_dict()
|
||||
node_extra_info_groups.append(node_extra_info_groups_item)
|
||||
|
||||
children: Union[Unset, list[dict[str, Any]]] = UNSET
|
||||
if not isinstance(self.children, Unset):
|
||||
children = []
|
||||
for children_item_data in self.children:
|
||||
children_item = children_item_data.to_dict()
|
||||
children.append(children_item)
|
||||
|
||||
field_dict: dict[str, Any] = {}
|
||||
field_dict.update(self.additional_properties)
|
||||
field_dict.update(
|
||||
{
|
||||
"node": node,
|
||||
}
|
||||
)
|
||||
if node_extra_info_groups is not UNSET:
|
||||
field_dict["node_extra_info_groups"] = node_extra_info_groups
|
||||
if children is not UNSET:
|
||||
field_dict["children"] = children
|
||||
|
||||
return field_dict
|
||||
|
||||
def to_multipart(self) -> types.RequestFiles:
|
||||
files: types.RequestFiles = []
|
||||
|
||||
files.append(("node", (None, str(self.node).encode(), "text/plain")))
|
||||
|
||||
if not isinstance(self.node_extra_info_groups, Unset):
|
||||
for node_extra_info_groups_item_element in self.node_extra_info_groups:
|
||||
files.append(
|
||||
(
|
||||
"node_extra_info_groups",
|
||||
(None, json.dumps(node_extra_info_groups_item_element.to_dict()).encode(), "application/json"),
|
||||
)
|
||||
)
|
||||
|
||||
if not isinstance(self.children, Unset):
|
||||
for children_item_element in self.children:
|
||||
files.append(
|
||||
("children", (None, json.dumps(children_item_element.to_dict()).encode(), "application/json"))
|
||||
)
|
||||
|
||||
for prop_name, prop in self.additional_properties.items():
|
||||
files.append((prop_name, (None, str(prop).encode(), "text/plain")))
|
||||
|
||||
return files
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
||||
from ..models.add_to_basket_node_extra_info_group import AddToBasketNodeExtraInfoGroup
|
||||
|
||||
d = dict(src_dict)
|
||||
node = d.pop("node")
|
||||
|
||||
node_extra_info_groups = []
|
||||
_node_extra_info_groups = d.pop("node_extra_info_groups", UNSET)
|
||||
for node_extra_info_groups_item_data in _node_extra_info_groups or []:
|
||||
node_extra_info_groups_item = AddToBasketNodeExtraInfoGroup.from_dict(node_extra_info_groups_item_data)
|
||||
|
||||
node_extra_info_groups.append(node_extra_info_groups_item)
|
||||
|
||||
children = []
|
||||
_children = d.pop("children", UNSET)
|
||||
for children_item_data in _children or []:
|
||||
children_item = SelectedNodeCreation.from_dict(children_item_data)
|
||||
|
||||
children.append(children_item)
|
||||
|
||||
selected_node_creation = cls(
|
||||
node=node,
|
||||
node_extra_info_groups=node_extra_info_groups,
|
||||
children=children,
|
||||
)
|
||||
|
||||
selected_node_creation.additional_properties = d
|
||||
return selected_node_creation
|
||||
|
||||
@property
|
||||
def additional_keys(self) -> list[str]:
|
||||
return list(self.additional_properties.keys())
|
||||
|
||||
def __getitem__(self, key: str) -> Any:
|
||||
return self.additional_properties[key]
|
||||
|
||||
def __setitem__(self, key: str, value: Any) -> None:
|
||||
self.additional_properties[key] = value
|
||||
|
||||
def __delitem__(self, key: str) -> None:
|
||||
del self.additional_properties[key]
|
||||
|
||||
def __contains__(self, key: str) -> bool:
|
||||
return key in self.additional_properties
|
||||
Reference in New Issue
Block a user