Skip to content

Commit

Permalink
feat: Support sending fields with null value (box/box-codegen#528) (#…
Browse files Browse the repository at this point in the history
…230)

Fixes: #202
  • Loading branch information
box-sdk-build authored Jul 22, 2024
1 parent c565383 commit f91076e
Show file tree
Hide file tree
Showing 21 changed files with 252 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "f6b5758", "specHash": "d36b9f0", "version": "1.1.0" }
{ "engineHash": "5972afb", "specHash": "d36b9f0", "version": "1.1.0" }
2 changes: 2 additions & 0 deletions box_sdk_gen/internal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from box_sdk_gen.internal.base_object import *

from box_sdk_gen.internal.null_value import *

from box_sdk_gen.internal.utils import *
5 changes: 4 additions & 1 deletion box_sdk_gen/internal/base_object.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, date
from enum import EnumMeta, Enum
from typing import get_args, get_origin, Union, Optional
from .null_value import NullValue


class BaseObject:
Expand All @@ -27,7 +28,9 @@ def to_dict(self) -> dict:
for k, v in vars(self).items():
if v is None:
continue
if type(v) is list:
if isinstance(v, NullValue):
value = None
elif type(v) is list:
value = [
item.to_dict() if isinstance(item, BaseObject) else item
for item in v
Expand Down
5 changes: 5 additions & 0 deletions box_sdk_gen/internal/null_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class NullValue:
pass


null = NullValue()
5 changes: 5 additions & 0 deletions box_sdk_gen/internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .base_object import BaseObject
from ..serialization.json.json_data import sd_to_json
from ..serialization.json.serializer import serialize
from .null_value import null

ByteStream = BufferedIOBase
Buffer = bytes
Expand Down Expand Up @@ -304,3 +305,7 @@ def date_time_to_string(date_time: DateTime) -> str:

def date_time_from_string(date_time: str) -> DateTime:
return DateTime.fromisoformat(date_time.replace('Z', '+00:00'))


def create_null():
return null
8 changes: 6 additions & 2 deletions box_sdk_gen/managers/file_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

from box_sdk_gen.serialization.json.serializer import deserialize

from box_sdk_gen.internal.null_value import NullValue

from typing import Union

from box_sdk_gen.serialization.json.serializer import serialize

from box_sdk_gen.schemas.file_versions import FileVersions
Expand Down Expand Up @@ -200,7 +204,7 @@ def update_file_version_by_id(
file_id: str,
file_version_id: str,
*,
trashed_at: Optional[str] = None,
trashed_at: Union[Optional[str], NullValue] = None,
extra_headers: Optional[Dict[str, Optional[str]]] = None
) -> FileVersionFull:
"""
Expand Down Expand Up @@ -228,7 +232,7 @@ def update_file_version_by_id(
:type file_version_id: str
:param trashed_at: Set this to `null` to clear
the date and restore the file., defaults to None
:type trashed_at: Optional[str], optional
:type trashed_at: Union[Optional[str], NullValue], optional
:param extra_headers: Extra headers that will be included in the HTTP request., defaults to None
:type extra_headers: Optional[Dict[str, Optional[str]]], optional
"""
Expand Down
14 changes: 9 additions & 5 deletions box_sdk_gen/managers/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

from box_sdk_gen.serialization.json.serializer import deserialize

from box_sdk_gen.internal.null_value import NullValue

from typing import Union

from box_sdk_gen.serialization.json.serializer import serialize

from box_sdk_gen.schemas.file_full import FileFull
Expand Down Expand Up @@ -330,11 +334,11 @@ def update_file_by_id(
name: Optional[str] = None,
description: Optional[str] = None,
parent: Optional[UpdateFileByIdParent] = None,
shared_link: Optional[UpdateFileByIdSharedLink] = None,
lock: Optional[UpdateFileByIdLock] = None,
shared_link: Union[Optional[UpdateFileByIdSharedLink], NullValue] = None,
lock: Union[Optional[UpdateFileByIdLock], NullValue] = None,
disposition_at: Optional[DateTime] = None,
permissions: Optional[UpdateFileByIdPermissions] = None,
collections: Optional[List[UpdateFileByIdCollections]] = None,
collections: Union[Optional[List[UpdateFileByIdCollections]], NullValue] = None,
tags: Optional[List[str]] = None,
fields: Optional[List[str]] = None,
if_match: Optional[str] = None,
Expand Down Expand Up @@ -367,7 +371,7 @@ def update_file_by_id(
who created the lock.
Set this to `null` to remove the lock., defaults to None
:type lock: Optional[UpdateFileByIdLock], optional
:type lock: Union[Optional[UpdateFileByIdLock], NullValue], optional
:param disposition_at: The retention expiration timestamp for the given file. This
date cannot be shortened once set on a file., defaults to None
:type disposition_at: Optional[DateTime], optional
Expand All @@ -384,7 +388,7 @@ def update_file_by_id(
the file from all collections.
[1]: e://get-collections, defaults to None
:type collections: Optional[List[UpdateFileByIdCollections]], optional
:type collections: Union[Optional[List[UpdateFileByIdCollections]], NullValue], optional
:param tags: The tags for this item. These tags are shown in
the Box web app and mobile apps next to an item.
Expand Down
14 changes: 11 additions & 3 deletions box_sdk_gen/managers/folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

from box_sdk_gen.serialization.json.serializer import deserialize

from box_sdk_gen.internal.null_value import NullValue

from typing import Union

from box_sdk_gen.serialization.json.serializer import serialize

from box_sdk_gen.schemas.folder_full import FolderFull
Expand Down Expand Up @@ -440,10 +444,14 @@ def update_folder_by_id(
can_non_owners_invite: Optional[bool] = None,
parent: Optional[UpdateFolderByIdParent] = None,
shared_link: Optional[UpdateFolderByIdSharedLink] = None,
folder_upload_email: Optional[UpdateFolderByIdFolderUploadEmail] = None,
folder_upload_email: Union[
Optional[UpdateFolderByIdFolderUploadEmail], NullValue
] = None,
tags: Optional[List[str]] = None,
is_collaboration_restricted_to_enterprise: Optional[bool] = None,
collections: Optional[List[UpdateFolderByIdCollections]] = None,
collections: Union[
Optional[List[UpdateFolderByIdCollections]], NullValue
] = None,
can_non_owners_view_collaborators: Optional[bool] = None,
fields: Optional[List[str]] = None,
if_match: Optional[str] = None,
Expand Down Expand Up @@ -504,7 +512,7 @@ def update_folder_by_id(
the folder from all collections.
[1]: e://get-collections, defaults to None
:type collections: Optional[List[UpdateFolderByIdCollections]], optional
:type collections: Union[Optional[List[UpdateFolderByIdCollections]], NullValue], optional
:param can_non_owners_view_collaborators: Restricts collaborators who are not the owner of
this folder from viewing other collaborations on
this folder.
Expand Down
12 changes: 8 additions & 4 deletions box_sdk_gen/managers/memberships.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

from box_sdk_gen.serialization.json.serializer import deserialize

from box_sdk_gen.internal.null_value import NullValue

from typing import Union

from typing import List

from box_sdk_gen.serialization.json.serializer import serialize
Expand Down Expand Up @@ -201,7 +205,7 @@ def create_group_membership(
group: CreateGroupMembershipGroup,
*,
role: Optional[CreateGroupMembershipRole] = None,
configurable_permissions: Optional[Dict[str, bool]] = None,
configurable_permissions: Union[Optional[Dict[str, bool]], NullValue] = None,
fields: Optional[List[str]] = None,
extra_headers: Optional[Dict[str, Optional[str]]] = None
) -> GroupMembership:
Expand All @@ -226,7 +230,7 @@ def create_group_membership(
Specifying a value of `null` for this object will disable
all configurable permissions. Specifying permissions will set
them accordingly, omitted permissions will be enabled by default., defaults to None
:type configurable_permissions: Optional[Dict[str, bool]], optional
:type configurable_permissions: Union[Optional[Dict[str, bool]], NullValue], optional
:param fields: A comma-separated list of attributes to include in the
response. This can be used to request fields that are
not normally returned in a standard response.
Expand Down Expand Up @@ -326,7 +330,7 @@ def update_group_membership_by_id(
group_membership_id: str,
*,
role: Optional[UpdateGroupMembershipByIdRole] = None,
configurable_permissions: Optional[Dict[str, bool]] = None,
configurable_permissions: Union[Optional[Dict[str, bool]], NullValue] = None,
fields: Optional[List[str]] = None,
extra_headers: Optional[Dict[str, Optional[str]]] = None
) -> GroupMembership:
Expand All @@ -353,7 +357,7 @@ def update_group_membership_by_id(
Specifying a value of `null` for this object will disable
all configurable permissions. Specifying permissions will set
them accordingly, omitted permissions will be enabled by default., defaults to None
:type configurable_permissions: Optional[Dict[str, bool]], optional
:type configurable_permissions: Union[Optional[Dict[str, bool]], NullValue], optional
:param fields: A comma-separated list of attributes to include in the
response. This can be used to request fields that are
not normally returned in a standard response.
Expand Down
34 changes: 20 additions & 14 deletions box_sdk_gen/managers/retention_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

from box_sdk_gen.serialization.json.serializer import serialize

from box_sdk_gen.internal.null_value import NullValue

from typing import Union

from box_sdk_gen.schemas.retention_policies import RetentionPolicies

from box_sdk_gen.schemas.client_error import ClientError
Expand Down Expand Up @@ -291,15 +295,17 @@ def update_retention_policy_by_id(
self,
retention_policy_id: str,
*,
policy_name: Optional[str] = None,
description: Optional[str] = None,
policy_name: Union[Optional[str], NullValue] = None,
description: Union[Optional[str], NullValue] = None,
disposition_action: Optional[str] = None,
retention_type: Optional[str] = None,
retention_type: Union[Optional[str], NullValue] = None,
retention_length: Optional[str] = None,
status: Optional[str] = None,
can_owner_extend_retention: Optional[bool] = None,
are_owners_notified: Optional[bool] = None,
custom_notification_recipients: Optional[List[UserBase]] = None,
status: Union[Optional[str], NullValue] = None,
can_owner_extend_retention: Union[Optional[bool], NullValue] = None,
are_owners_notified: Union[Optional[bool], NullValue] = None,
custom_notification_recipients: Union[
Optional[List[UserBase]], NullValue
] = None,
extra_headers: Optional[Dict[str, Optional[str]]] = None
) -> RetentionPolicy:
"""
Expand All @@ -308,9 +314,9 @@ def update_retention_policy_by_id(
Example: "982312"
:type retention_policy_id: str
:param policy_name: The name for the retention policy, defaults to None
:type policy_name: Optional[str], optional
:type policy_name: Union[Optional[str], NullValue], optional
:param description: The additional text description of the retention policy., defaults to None
:type description: Optional[str], optional
:type description: Union[Optional[str], NullValue], optional
:param disposition_action: The disposition action of the retention policy.
This action can be `permanently_delete`, which
will cause the content retained by the policy
Expand Down Expand Up @@ -339,7 +345,7 @@ def update_retention_policy_by_id(
`non-modifiable` type only. You can convert a
`modifiable` policy to `non-modifiable`, but
not the other way around., defaults to None
:type retention_type: Optional[str], optional
:type retention_type: Union[Optional[str], NullValue], optional
:param retention_length: The length of the retention policy. This value
specifies the duration in days that the retention
policy will be active for after being assigned to
Expand All @@ -351,17 +357,17 @@ def update_retention_policy_by_id(
If not retiring a policy, do not include this parameter
or set it to `null`., defaults to None
:type status: Optional[str], optional
:type status: Union[Optional[str], NullValue], optional
:param can_owner_extend_retention: Determines if the owner of items under the policy
can extend the retention when the original retention
duration is about to end., defaults to None
:type can_owner_extend_retention: Optional[bool], optional
:type can_owner_extend_retention: Union[Optional[bool], NullValue], optional
:param are_owners_notified: Determines if owners and co-owners of items
under the policy are notified when
the retention duration is about to end., defaults to None
:type are_owners_notified: Optional[bool], optional
:type are_owners_notified: Union[Optional[bool], NullValue], optional
:param custom_notification_recipients: A list of users notified when the retention duration is about to end., defaults to None
:type custom_notification_recipients: Optional[List[UserBase]], optional
:type custom_notification_recipients: Union[Optional[List[UserBase]], NullValue], optional
:param extra_headers: Extra headers that will be included in the HTTP request., defaults to None
:type extra_headers: Optional[Dict[str, Optional[str]]], optional
"""
Expand Down
10 changes: 8 additions & 2 deletions box_sdk_gen/managers/shared_links_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

from box_sdk_gen.serialization.json.serializer import serialize

from box_sdk_gen.internal.null_value import NullValue

from typing import Union

from box_sdk_gen.schemas.file_full import FileFull

from box_sdk_gen.schemas.client_error import ClientError
Expand Down Expand Up @@ -479,7 +483,9 @@ def remove_shared_link_from_file(
file_id: str,
fields: str,
*,
shared_link: Optional[RemoveSharedLinkFromFileSharedLink] = None,
shared_link: Union[
Optional[RemoveSharedLinkFromFileSharedLink], NullValue
] = None,
extra_headers: Optional[Dict[str, Optional[str]]] = None
) -> FileFull:
"""
Expand All @@ -498,7 +504,7 @@ def remove_shared_link_from_file(
:type fields: str
:param shared_link: By setting this value to `null`, the shared link
is removed from the file., defaults to None
:type shared_link: Optional[RemoveSharedLinkFromFileSharedLink], optional
:type shared_link: Union[Optional[RemoveSharedLinkFromFileSharedLink], NullValue], optional
:param extra_headers: Extra headers that will be included in the HTTP request., defaults to None
:type extra_headers: Optional[Dict[str, Optional[str]]], optional
"""
Expand Down
10 changes: 8 additions & 2 deletions box_sdk_gen/managers/shared_links_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

from box_sdk_gen.serialization.json.serializer import serialize

from box_sdk_gen.internal.null_value import NullValue

from typing import Union

from box_sdk_gen.schemas.folder_full import FolderFull

from box_sdk_gen.schemas.client_error import ClientError
Expand Down Expand Up @@ -481,7 +485,9 @@ def remove_shared_link_from_folder(
folder_id: str,
fields: str,
*,
shared_link: Optional[RemoveSharedLinkFromFolderSharedLink] = None,
shared_link: Union[
Optional[RemoveSharedLinkFromFolderSharedLink], NullValue
] = None,
extra_headers: Optional[Dict[str, Optional[str]]] = None
) -> FolderFull:
"""
Expand All @@ -503,7 +509,7 @@ def remove_shared_link_from_folder(
:type fields: str
:param shared_link: By setting this value to `null`, the shared link
is removed from the folder., defaults to None
:type shared_link: Optional[RemoveSharedLinkFromFolderSharedLink], optional
:type shared_link: Union[Optional[RemoveSharedLinkFromFolderSharedLink], NullValue], optional
:param extra_headers: Extra headers that will be included in the HTTP request., defaults to None
:type extra_headers: Optional[Dict[str, Optional[str]]], optional
"""
Expand Down
10 changes: 8 additions & 2 deletions box_sdk_gen/managers/shared_links_web_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

from box_sdk_gen.serialization.json.serializer import serialize

from box_sdk_gen.internal.null_value import NullValue

from typing import Union

from box_sdk_gen.schemas.web_link import WebLink

from box_sdk_gen.schemas.client_error import ClientError
Expand Down Expand Up @@ -452,7 +456,9 @@ def remove_shared_link_from_web_link(
web_link_id: str,
fields: str,
*,
shared_link: Optional[RemoveSharedLinkFromWebLinkSharedLink] = None,
shared_link: Union[
Optional[RemoveSharedLinkFromWebLinkSharedLink], NullValue
] = None,
extra_headers: Optional[Dict[str, Optional[str]]] = None
) -> WebLink:
"""
Expand All @@ -465,7 +471,7 @@ def remove_shared_link_from_web_link(
:type fields: str
:param shared_link: By setting this value to `null`, the shared link
is removed from the web link., defaults to None
:type shared_link: Optional[RemoveSharedLinkFromWebLinkSharedLink], optional
:type shared_link: Union[Optional[RemoveSharedLinkFromWebLinkSharedLink], NullValue], optional
:param extra_headers: Extra headers that will be included in the HTTP request., defaults to None
:type extra_headers: Optional[Dict[str, Optional[str]]], optional
"""
Expand Down
Loading

0 comments on commit f91076e

Please sign in to comment.