Skip to content

Commit a76f30f

Browse files
committed
Add base64 encoding support for bytes in ApiClient and update .openapi-generator-ignore
1 parent 033f046 commit a76f30f

File tree

6 files changed

+28
-3
lines changed

6 files changed

+28
-3
lines changed

build.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
if [ -z "$1" ]; then
4+
echo "Use: $0 <version> (ex: 10_10 or 10_11)"
5+
exit 1
6+
fi
7+
8+
VERSION="$1"
9+
10+
openapi-generator-cli generate -g python \
11+
-t ./templates/python \
12+
-i ./specs/openapi_${VERSION}.json \
13+
-p packageName=jellyfin.generated.api_${VERSION},packageVersion=${VERSION/_/.} \
14+
-o ./src/

src/.openapi-generator-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ setup.cfg
1212
tox.ini
1313
pyproject.toml
1414
jellyfin/__init__.py
15+
jellyfin/generated/__init__.py
1516
.openapi-generator/

src/jellyfin/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def client(self) -> ApiClient:
8080
"""Returns the ApiClient instance."""
8181
if self._client is None:
8282
self._client = self.generated.ApiClient(self.configuration)
83+
self.generated.ApiClient.set_default(self._client)
8384
return self._client
8485

8586
def register_client(self, client_name: str = None, device_name: str = None, device_id: str = None, device_version: str = None) -> Self:

src/jellyfin/generated/api_10_10/api_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Do not edit the class manually.
1212
""" # noqa: E501
1313

14-
14+
import base64
1515
import datetime
1616
from dateutil.parser import parse
1717
from enum import Enum
@@ -353,6 +353,9 @@ def sanitize_for_serialization(self, obj):
353353
return None
354354
elif isinstance(obj, Enum):
355355
return obj.value
356+
elif isinstance(obj, bytes):
357+
# https://github.com/jellyfin/jellyfin/issues/12447#issuecomment-2292569926
358+
return base64.b64encode(obj).decode("utf-8")
356359
elif isinstance(obj, SecretStr):
357360
return obj.get_secret_value()
358361
elif isinstance(obj, self.PRIMITIVE_TYPES):

src/jellyfin/generated/api_10_11/api_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Do not edit the class manually.
1212
""" # noqa: E501
1313

14-
14+
import base64
1515
import datetime
1616
from dateutil.parser import parse
1717
from enum import Enum
@@ -353,6 +353,9 @@ def sanitize_for_serialization(self, obj):
353353
return None
354354
elif isinstance(obj, Enum):
355355
return obj.value
356+
elif isinstance(obj, bytes):
357+
# https://github.com/jellyfin/jellyfin/issues/12447#issuecomment-2292569926
358+
return base64.b64encode(obj).decode("utf-8")
356359
elif isinstance(obj, SecretStr):
357360
return obj.get_secret_value()
358361
elif isinstance(obj, self.PRIMITIVE_TYPES):

templates/python/api_client.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{{>partial_header}}
44

5-
5+
import base64
66
import datetime
77
from dateutil.parser import parse
88
from enum import Enum
@@ -362,6 +362,9 @@ class ApiClient:
362362
return None
363363
elif isinstance(obj, Enum):
364364
return obj.value
365+
elif isinstance(obj, bytes):
366+
# https://github.com/jellyfin/jellyfin/issues/12447#issuecomment-2292569926
367+
return base64.b64encode(obj).decode("utf-8")
365368
elif isinstance(obj, SecretStr):
366369
return obj.get_secret_value()
367370
elif isinstance(obj, self.PRIMITIVE_TYPES):

0 commit comments

Comments
 (0)