Skip to content

Commit

Permalink
codegen output b495717cf2b2481f83a20ea8422f2674 (#39)
Browse files Browse the repository at this point in the history
* generated with codegen at box/box-codegen@a1233bf and spec at box/box-openapi@c1e2439

* generated with codegen at box/box-codegen@78cfd9f and spec at box/box-openapi@70477a9

* generated with codegen at box/box-codegen@78cfd9f and spec at box/box-openapi@f87c74a

* generated with codegen at box/box-codegen@87a1b04 and spec at box/box-openapi@340803e

* generated with codegen at box/box-codegen@bce9879 and spec at box/box-openapi@199dd2f

* generated with codegen at box/box-codegen@651f5cf and spec at box/box-openapi@cd2efc9

* generated with codegen at box/box-codegen@dc7d480 and spec at box/box-openapi@644ca90
  • Loading branch information
box-sdk-build authored Oct 20, 2023
1 parent b59c14c commit 9bc8ceb
Show file tree
Hide file tree
Showing 120 changed files with 2,018 additions and 1,278 deletions.
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Bug
about: Report a bug found in the SDK
title: ''
labels: bug
assignees: mwwoda, mhagmajer, antusus, arjankowski, lukaszsocha2, bartlomiejleszczynski
assignees: mwwoda, mhagmajer, arjankowski, lukaszsocha2, bartlomiejleszczynski, congminh1254
---

- [ ] I have checked that the [SDK documentation][sdk-docs] doesn't solve my issue.
Expand Down Expand Up @@ -48,7 +48,8 @@ assignees: mwwoda, mhagmajer, antusus, arjankowski, lukaszsocha2, bartlomiejlesz
Python SDK: <!-- Replace with the version of the Python SDK you're using. -->
Python: <!-- Replace with the version of Python your application is running on. -->

[sdk-docs]: https://github.com/box/box-python-sdk-generated/tree/main/docs

[sdk-docs]: https://github.com/box/box-python-sdk-gen/tree/main/docs
[api-docs]: https://developer.box.com/docs
[dev-forums]: https://community.box.com/t5/Platform-and-Development-Forum/bd-p/DeveloperForum
[github-repo]: https://github.com/box/box-python-sdk-generated/search?type=Issues
[github-repo]: https://github.com/box/box-python-sdk-gen/search?type=Issues
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/enhancement.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Enhancement
about: Suggest a new feature or change
title: ''
labels: enhancement
assignees: mwwoda, mhagmajer, antusus, arjankowski, lukaszsocha2, bartlomiejleszczynski
assignees: mwwoda, mhagmajer, arjankowski, lukaszsocha2, bartlomiejleszczynski, congminh1254
---

### Is your feature request related to a problem? Please describe.
Expand Down
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Question
about: Request for Assistance
title: ''
labels: question
assignees: mwwoda, mhagmajer, antusus, arjankowski, lukaszsocha2, bartlomiejleszczynski
assignees: mwwoda, mhagmajer, arjankowski, lukaszsocha2, bartlomiejleszczynski, congminh1254
---

- [ ] I have checked that the [SDK documentation][sdk-docs] doesn't solve my issue.
Expand Down Expand Up @@ -48,7 +48,8 @@ assignees: mwwoda, mhagmajer, antusus, arjankowski, lukaszsocha2, bartlomiejlesz
Python SDK: <!-- Replace with the version of the Python SDK you're using. -->
Python: <!-- Replace with the version of Python your application is running on. -->

[sdk-docs]: https://github.com/box/box-python-sdk-generated/tree/main/docs

[sdk-docs]: https://github.com/box/box-python-sdk-gen/tree/main/docs
[api-docs]: https://developer.box.com/docs
[dev-forums]: https://community.box.com/t5/Platform-and-Development-Forum/bd-p/DeveloperForum
[github-repo]: https://github.com/box/box-python-sdk-generated/search?type=Issues
[github-repo]: https://github.com/box/box-python-sdk-gen/search?type=Issues
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Embrace the new generation of Box SDKs and unlock the full potential of the Box
pip install box-sdk-gen
```

This is autogenerated Box SDK Beta version. The engine used for generating this SDK can be found [here](https://github.com/box/box-codegen).
This is autogenerated Box SDK Beta version.
Supported Python versions are Python 3.8 and above.

To install also extra dependencies required for JWT authentication, use command:
Expand Down
50 changes: 31 additions & 19 deletions box_sdk_gen/base_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def from_dict(cls, data: dict):
for key, value in data.items():
mapping_field_name = cls._json_to_fields_mapping.get(key, key)
annotation = cls.__init__.__annotations__.get(mapping_field_name, None)
unpacked_attributes[mapping_field_name] = cls.__deserialize(
unpacked_attributes[mapping_field_name] = cls._deserialize(
key, value, annotation
)
return cls(**unpacked_attributes)
Expand All @@ -41,66 +41,78 @@ def to_dict(self) -> dict:
return result_dict

@classmethod
def __deserialize(cls, key, value, annotation=None):
def _deserialize(cls, key, value, annotation=None):
if annotation is None:
return value
if get_origin(annotation) == Optional:
return cls.__deserialize(key, value, get_args(annotation))
return cls._deserialize(key, value, get_args(annotation))
if get_origin(annotation) == Union:
union_without_none_type = [
arg for arg in get_args(annotation) if arg is not type(None)
]
if len(union_without_none_type) == 1:
return cls.__deserialize(key, value, union_without_none_type[0])
return cls._deserialize(key, value, union_without_none_type[0])

if get_origin(annotation) == list:
return cls.__deserialize_list(key, value, annotation)
return cls._deserialize_list(key, value, annotation)
elif get_origin(annotation) == Union:
return cls.__deserialize_union(key, value, annotation)
return cls._deserialize_union(key, value, annotation)
elif isinstance(annotation, EnumMeta):
return cls.__deserialize_enum(key, value, annotation)
return cls._deserialize_enum(key, value, annotation)
else:
return cls.__deserialize_nested_type(key, value, annotation)
return cls._deserialize_nested_type(key, value, annotation)

@classmethod
def __deserialize_list(cls, key, value, annotation: list):
def _deserialize_list(cls, key, value, annotation: list):
list_type = get_args(annotation)[0]
try:
return [
cls.__deserialize(key, list_entry, list_type) for list_entry in value
cls._deserialize(key, list_entry, list_type) for list_entry in value
]
except Exception:
return value

@classmethod
def __deserialize_union(cls, key, value, annotation):
def _deserialize_union(cls, key, value, annotation):
possible_types = get_args(annotation)
type_field_value = value.get('type', None) or value.get('skillCardType', None)
if 'type' in value:
type_field = 'type'
else:
type_field = 'skillCardType'
type_field_value = value.get(type_field, None)

type = None
for i, possible_type in enumerate(possible_types):
# remove special characters
if type_field_value.replace("_", "") in possible_types[i].__name__.lower():
type = possible_types[i]
break
try:
if (
type_field_value.replace("_", "")
in possible_types[i].__name__.lower()
or possible_types[i].__init__.__annotations__[type_field][
type_field_value.upper()
]
):
type = possible_types[i]
break
except Exception:
continue

if not type:
print('Could not deserialize Union: ', annotation, 'of value:', value)

try:
return cls.__deserialize(key, value, type)
return cls._deserialize(key, value, type)
except Exception:
return value

@classmethod
def __deserialize_enum(cls, key, value, annotation):
def _deserialize_enum(cls, key, value, annotation):
try:
return getattr(annotation, value.upper().replace(' ', '_'))
except Exception:
return value

@classmethod
def __deserialize_nested_type(cls, key, value, annotation):
def _deserialize_nested_type(cls, key, value, annotation):
try:
return annotation.from_dict(value)
except Exception:
Expand Down
2 changes: 2 additions & 0 deletions box_sdk_gen/managers/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from typing import Dict

from box_sdk_gen.utils import to_string

from box_sdk_gen.schemas import AccessToken

from box_sdk_gen.schemas import OAuth2Error
Expand Down
24 changes: 13 additions & 11 deletions box_sdk_gen/managers/avatars.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import Dict

from box_sdk_gen.serialization import deserialize
from box_sdk_gen.utils import to_string

from box_sdk_gen.base_object import BaseObject
from box_sdk_gen.serialization import deserialize

from box_sdk_gen.schemas import ClientError

Expand Down Expand Up @@ -53,7 +53,7 @@ def get_user_avatar(
extra_headers = {}
headers_map: Dict[str, str] = prepare_params({**extra_headers})
response: FetchResponse = fetch(
''.join(['https://api.box.com/2.0/users/', user_id, '/avatar']),
''.join(['https://api.box.com/2.0/users/', to_string(user_id), '/avatar']),
FetchOptions(
method='GET',
headers=headers_map,
Expand Down Expand Up @@ -86,21 +86,23 @@ def create_user_avatar(
"""
if extra_headers is None:
extra_headers = {}
request_body = BaseObject(
pic=pic, pic_file_name=pic_file_name, pic_content_type=pic_content_type
)
request_body = {
'pic': pic,
'pic_file_name': pic_file_name,
'pic_content_type': pic_content_type,
}
headers_map: Dict[str, str] = prepare_params({**extra_headers})
response: FetchResponse = fetch(
''.join(['https://api.box.com/2.0/users/', user_id, '/avatar']),
''.join(['https://api.box.com/2.0/users/', to_string(user_id), '/avatar']),
FetchOptions(
method='POST',
headers=headers_map,
multipart_data=[
MultipartItem(
part_name='pic',
file_stream=request_body.pic,
file_name=request_body.pic_file_name,
content_type=request_body.pic_content_type,
file_stream=request_body['pic'],
file_name=request_body['pic_file_name'],
content_type=request_body['pic_content_type'],
)
],
content_type='multipart/form-data',
Expand Down Expand Up @@ -129,7 +131,7 @@ def delete_user_avatar(
extra_headers = {}
headers_map: Dict[str, str] = prepare_params({**extra_headers})
response: FetchResponse = fetch(
''.join(['https://api.box.com/2.0/users/', user_id, '/avatar']),
''.join(['https://api.box.com/2.0/users/', to_string(user_id), '/avatar']),
FetchOptions(
method='DELETE',
headers=headers_map,
Expand Down
30 changes: 18 additions & 12 deletions box_sdk_gen/managers/chunked_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from box_sdk_gen.serialization import deserialize

from box_sdk_gen.base_object import BaseObject
from box_sdk_gen.utils import to_string

from box_sdk_gen.utils import Buffer

Expand Down Expand Up @@ -106,9 +106,11 @@ def create_file_upload_session(
"""
if extra_headers is None:
extra_headers = {}
request_body = BaseObject(
folder_id=folder_id, file_size=file_size, file_name=file_name
)
request_body = {
'folder_id': folder_id,
'file_size': file_size,
'file_name': file_name,
}
headers_map: Dict[str, str] = prepare_params({**extra_headers})
response: FetchResponse = fetch(
''.join(['https://upload.box.com/api/2.0/files/upload_sessions']),
Expand Down Expand Up @@ -150,11 +152,15 @@ def create_file_upload_session_for_existing_file(
"""
if extra_headers is None:
extra_headers = {}
request_body = BaseObject(file_size=file_size, file_name=file_name)
request_body = {'file_size': file_size, 'file_name': file_name}
headers_map: Dict[str, str] = prepare_params({**extra_headers})
response: FetchResponse = fetch(
''.join(
['https://upload.box.com/api/2.0/files/', file_id, '/upload_sessions']
[
'https://upload.box.com/api/2.0/files/',
to_string(file_id),
'/upload_sessions',
]
),
FetchOptions(
method='POST',
Expand Down Expand Up @@ -188,7 +194,7 @@ def get_file_upload_session_by_id(
''.join(
[
'https://upload.box.com/api/2.0/files/upload_sessions/',
upload_session_id,
to_string(upload_session_id),
]
),
FetchOptions(
Expand Down Expand Up @@ -252,7 +258,7 @@ def upload_file_part(
''.join(
[
'https://upload.box.com/api/2.0/files/upload_sessions/',
upload_session_id,
to_string(upload_session_id),
]
),
FetchOptions(
Expand Down Expand Up @@ -290,7 +296,7 @@ def delete_file_upload_session_by_id(
''.join(
[
'https://upload.box.com/api/2.0/files/upload_sessions/',
upload_session_id,
to_string(upload_session_id),
]
),
FetchOptions(
Expand Down Expand Up @@ -338,7 +344,7 @@ def get_file_upload_session_parts(
''.join(
[
'https://upload.box.com/api/2.0/files/upload_sessions/',
upload_session_id,
to_string(upload_session_id),
'/parts',
]
),
Expand Down Expand Up @@ -396,7 +402,7 @@ def create_file_upload_session_commit(
"""
if extra_headers is None:
extra_headers = {}
request_body = BaseObject(parts=parts)
request_body = {'parts': parts}
headers_map: Dict[str, str] = prepare_params(
{
'digest': to_string(digest),
Expand All @@ -409,7 +415,7 @@ def create_file_upload_session_commit(
''.join(
[
'https://upload.box.com/api/2.0/files/upload_sessions/',
upload_session_id,
to_string(upload_session_id),
'/commit',
]
),
Expand Down
18 changes: 8 additions & 10 deletions box_sdk_gen/managers/classifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

from box_sdk_gen.serialization import serialize

from box_sdk_gen.base_object import BaseObject

from box_sdk_gen.schemas import ClassificationTemplate

from box_sdk_gen.schemas import ClientError
Expand Down Expand Up @@ -702,14 +700,14 @@ def create_metadata_template_schema_classification(
"""
if extra_headers is None:
extra_headers = {}
request_body = BaseObject(
scope=scope,
templateKey=template_key,
displayName=display_name,
hidden=hidden,
copyInstanceOnItemCopy=copy_instance_on_item_copy,
fields=fields,
)
request_body = {
'scope': scope,
'templateKey': template_key,
'displayName': display_name,
'hidden': hidden,
'copyInstanceOnItemCopy': copy_instance_on_item_copy,
'fields': fields,
}
headers_map: Dict[str, str] = prepare_params({**extra_headers})
response: FetchResponse = fetch(
''.join(
Expand Down
Loading

0 comments on commit 9bc8ceb

Please sign in to comment.