From 9b92e9f804815b6efd0e1bf70238489090b7c42a Mon Sep 17 00:00:00 2001
From: David Trattnig <david@subsquare.at>
Date: Thu, 4 Aug 2022 20:46:29 +0200
Subject: [PATCH] refact(api):  new open-api generated api version

hold multiple, upcoming timeslots for clock. #26
---
 src/aura_engine_api/rest/models/clock_info.py | 34 +++++++++----------
 src/aura_engine_api/rest/models/timeslot.py   | 34 ++++++++++---------
 src/aura_engine_api/rest/swagger/swagger.yaml | 22 ++++++++----
 src/aura_engine_api/rest/util.py              | 23 +++----------
 4 files changed, 55 insertions(+), 58 deletions(-)

diff --git a/src/aura_engine_api/rest/models/clock_info.py b/src/aura_engine_api/rest/models/clock_info.py
index 6798ad9..3cf0648 100644
--- a/src/aura_engine_api/rest/models/clock_info.py
+++ b/src/aura_engine_api/rest/models/clock_info.py
@@ -17,7 +17,7 @@ class ClockInfo(Model):
 
     Do not edit the class manually.
     """
-    def __init__(self, engine_source=None, current_track=None, current_playlogs=None, planned_playlist=None, current_timeslot=None, next_timeslot=None):  # noqa: E501
+    def __init__(self, engine_source=None, current_track=None, current_playlogs=None, planned_playlist=None, current_timeslot=None, upcoming_timeslots=None):  # noqa: E501
         """ClockInfo - a model defined in Swagger
 
         :param engine_source: The engine_source of this ClockInfo.  # noqa: E501
@@ -30,8 +30,8 @@ class ClockInfo(Model):
         :type planned_playlist: Playlist
         :param current_timeslot: The current_timeslot of this ClockInfo.  # noqa: E501
         :type current_timeslot: Timeslot
-        :param next_timeslot: The next_timeslot of this ClockInfo.  # noqa: E501
-        :type next_timeslot: Timeslot
+        :param upcoming_timeslots: The upcoming_timeslots of this ClockInfo.  # noqa: E501
+        :type upcoming_timeslots: List[Timeslot]
         """
         self.swagger_types = {
             'engine_source': int,
@@ -39,7 +39,7 @@ class ClockInfo(Model):
             'current_playlogs': List[PlayLog],
             'planned_playlist': Playlist,
             'current_timeslot': Timeslot,
-            'next_timeslot': Timeslot
+            'upcoming_timeslots': List[Timeslot]
         }
 
         self.attribute_map = {
@@ -48,14 +48,14 @@ class ClockInfo(Model):
             'current_playlogs': 'current_playlogs',
             'planned_playlist': 'planned_playlist',
             'current_timeslot': 'current_timeslot',
-            'next_timeslot': 'next_timeslot'
+            'upcoming_timeslots': 'upcoming_timeslots'
         }
         self._engine_source = engine_source
         self._current_track = current_track
         self._current_playlogs = current_playlogs
         self._planned_playlist = planned_playlist
         self._current_timeslot = current_timeslot
-        self._next_timeslot = next_timeslot
+        self._upcoming_timeslots = upcoming_timeslots
 
     @classmethod
     def from_dict(cls, dikt):
@@ -174,22 +174,22 @@ class ClockInfo(Model):
         self._current_timeslot = current_timeslot
 
     @property
-    def next_timeslot(self):
-        """Gets the next_timeslot of this ClockInfo.
+    def upcoming_timeslots(self):
+        """Gets the upcoming_timeslots of this ClockInfo.
 
 
-        :return: The next_timeslot of this ClockInfo.
-        :rtype: Timeslot
+        :return: The upcoming_timeslots of this ClockInfo.
+        :rtype: List[Timeslot]
         """
-        return self._next_timeslot
+        return self._upcoming_timeslots
 
-    @next_timeslot.setter
-    def next_timeslot(self, next_timeslot):
-        """Sets the next_timeslot of this ClockInfo.
+    @upcoming_timeslots.setter
+    def upcoming_timeslots(self, upcoming_timeslots):
+        """Sets the upcoming_timeslots of this ClockInfo.
 
 
-        :param next_timeslot: The next_timeslot of this ClockInfo.
-        :type next_timeslot: Timeslot
+        :param upcoming_timeslots: The upcoming_timeslots of this ClockInfo.
+        :type upcoming_timeslots: List[Timeslot]
         """
 
-        self._next_timeslot = next_timeslot
+        self._upcoming_timeslots = upcoming_timeslots
diff --git a/src/aura_engine_api/rest/models/timeslot.py b/src/aura_engine_api/rest/models/timeslot.py
index 0066079..c733a91 100644
--- a/src/aura_engine_api/rest/models/timeslot.py
+++ b/src/aura_engine_api/rest/models/timeslot.py
@@ -14,7 +14,7 @@ class Timeslot(Model):
 
     Do not edit the class manually.
     """
-    def __init__(self, show_name=None, show_id=None, timeslot_id=None, timeslot_start=None, timeslot_end=None, playlist_id=None, fallback_type=None):  # noqa: E501
+    def __init__(self, show_name=None, show_id=None, timeslot_id=None, timeslot_start=None, timeslot_end=None, playlist_id=None, playlist_type=None):  # noqa: E501
         """Timeslot - a model defined in Swagger
 
         :param show_name: The show_name of this Timeslot.  # noqa: E501
@@ -29,8 +29,8 @@ class Timeslot(Model):
         :type timeslot_end: datetime
         :param playlist_id: The playlist_id of this Timeslot.  # noqa: E501
         :type playlist_id: int
-        :param fallback_type: The fallback_type of this Timeslot.  # noqa: E501
-        :type fallback_type: int
+        :param playlist_type: The playlist_type of this Timeslot.  # noqa: E501
+        :type playlist_type: int
         """
         self.swagger_types = {
             'show_name': str,
@@ -39,7 +39,7 @@ class Timeslot(Model):
             'timeslot_start': datetime,
             'timeslot_end': datetime,
             'playlist_id': int,
-            'fallback_type': int
+            'playlist_type': int
         }
 
         self.attribute_map = {
@@ -49,7 +49,7 @@ class Timeslot(Model):
             'timeslot_start': 'timeslot_start',
             'timeslot_end': 'timeslot_end',
             'playlist_id': 'playlist_id',
-            'fallback_type': 'fallback_type'
+            'playlist_type': 'playlist_type'
         }
         self._show_name = show_name
         self._show_id = show_id
@@ -57,7 +57,7 @@ class Timeslot(Model):
         self._timeslot_start = timeslot_start
         self._timeslot_end = timeslot_end
         self._playlist_id = playlist_id
-        self._fallback_type = fallback_type
+        self._playlist_type = playlist_type
 
     @classmethod
     def from_dict(cls, dikt):
@@ -199,22 +199,24 @@ class Timeslot(Model):
         self._playlist_id = playlist_id
 
     @property
-    def fallback_type(self):
-        """Gets the fallback_type of this Timeslot.
+    def playlist_type(self):
+        """Gets the playlist_type of this Timeslot.
 
+        Indicates on which scheduling level the playlist was assigned to the timeslot (-1=fallback, 0=timeslot, 1=schedule, 2=show, 3=station)  # noqa: E501
 
-        :return: The fallback_type of this Timeslot.
+        :return: The playlist_type of this Timeslot.
         :rtype: int
         """
-        return self._fallback_type
+        return self._playlist_type
 
-    @fallback_type.setter
-    def fallback_type(self, fallback_type):
-        """Sets the fallback_type of this Timeslot.
+    @playlist_type.setter
+    def playlist_type(self, playlist_type):
+        """Sets the playlist_type of this Timeslot.
 
+        Indicates on which scheduling level the playlist was assigned to the timeslot (-1=fallback, 0=timeslot, 1=schedule, 2=show, 3=station)  # noqa: E501
 
-        :param fallback_type: The fallback_type of this Timeslot.
-        :type fallback_type: int
+        :param playlist_type: The playlist_type of this Timeslot.
+        :type playlist_type: int
         """
 
-        self._fallback_type = fallback_type
+        self._playlist_type = playlist_type
diff --git a/src/aura_engine_api/rest/swagger/swagger.yaml b/src/aura_engine_api/rest/swagger/swagger.yaml
index 632ed89..d25697a 100644
--- a/src/aura_engine_api/rest/swagger/swagger.yaml
+++ b/src/aura_engine_api/rest/swagger/swagger.yaml
@@ -623,14 +623,18 @@ components:
           $ref: '#/components/schemas/PlayLog'
         current_playlogs:
           type: array
+          nullable: true
           items:
             $ref: '#/components/schemas/PlayLog'
         planned_playlist:
           $ref: '#/components/schemas/Playlist'
         current_timeslot:
           $ref: '#/components/schemas/Timeslot'
-        next_timeslot:
-          $ref: '#/components/schemas/Timeslot'
+        upcoming_timeslots:
+          type: array
+          nullable: true
+          items:
+            $ref: '#/components/schemas/Timeslot'
       description: "Holds the most recent data required to display the studio clock.\
         \ The field `engine_source` will most likey be the same value as `current_track.log_source`.\
         \ This value represents which engine the record has been logged from. If it\
@@ -641,13 +645,16 @@ components:
         \ API, while the actual `ClockInfo` was logged from an engine instance instead."
       example:
         engine_source: 1
+        upcoming_timeslots:
+        - null
+        - null
         current_timeslot:
           show_id: 42
           timeslot_end: 2020-08-29T09:12:33.001Z
           playlist_id: 38
           show_name: Electronic Music from Brazil
-          fallback_type: 0
           timeslot_start: 2020-08-29T09:12:33.001Z
+          playlist_type: 0
           timeslot_id: 23
         current_playlogs:
         - null
@@ -667,7 +674,6 @@ components:
           log_source: 1
           track_duration: 808
           custom_json: "{ \"custom\": \"Stringified JSON Object\" }"
-        next_timeslot: null
         planned_playlist:
           entries:
           - track_album: Bricolage
@@ -709,9 +715,12 @@ components:
           example: 2020-08-29T09:12:33.001Z
         playlist_id:
           type: integer
+          nullable: true
           example: 38
-        fallback_type:
+        playlist_type:
           type: integer
+          description: "Indicates on which scheduling level the playlist was assigned\
+            \ to the timeslot (-1=fallback, 0=timeslot, 1=schedule, 2=show, 3=station)"
           example: 0
       description: Holds data describing some timeslot. Used by `ClockInfo` for the
         studio clock.
@@ -720,8 +729,8 @@ components:
         timeslot_end: 2020-08-29T09:12:33.001Z
         playlist_id: 38
         show_name: Electronic Music from Brazil
-        fallback_type: 0
         timeslot_start: 2020-08-29T09:12:33.001Z
+        playlist_type: 0
         timeslot_id: 23
     Playlist:
       required:
@@ -730,6 +739,7 @@ components:
       properties:
         playlist_id:
           type: integer
+          nullable: true
           example: 38
         entries:
           type: array
diff --git a/src/aura_engine_api/rest/util.py b/src/aura_engine_api/rest/util.py
index 0617adf..9bfac52 100644
--- a/src/aura_engine_api/rest/util.py
+++ b/src/aura_engine_api/rest/util.py
@@ -16,7 +16,7 @@ def _deserialize(data, klass):
     if data is None:
         return None
 
-    if klass in six.integer_types or klass in (float, str, bool):
+    if klass in six.integer_types or klass in (float, str, bool, bytearray):
         return _deserialize_primitive(data, klass)
     elif klass == object:
         return _deserialize_object(data)
@@ -24,30 +24,15 @@ def _deserialize(data, klass):
         return deserialize_date(data)
     elif klass == datetime.datetime:
         return deserialize_datetime(data)
-
-    # NOTE: Due to Python 3.7 not providing `typing.GenericMeta` anymore,
-    # this workaround is needed (See https://github.com/swagger-api/swagger-codegen/issues/8921)
-    # As soon this has been fixed in SwaggerHub Codegen this class can
-    # be replaced by the generated one again.
-    #
-    elif hasattr(klass, '__origin__'):
-        if klass.__origin__ == list:
+    elif type_util.is_generic(klass):
+        if type_util.is_list(klass):
             return _deserialize_list(data, klass.__args__[0])
-        if klass.__origin__ == dict:
+        if type_util.is_dict(klass):
             return _deserialize_dict(data, klass.__args__[1])
-
-    # Original generated fragment by Codegen (pre Python 3.7 compatible only):
-    #
-    # elif type(klass) == typing.GenericMeta:
-    #     if klass.__extra__ == list:
-    #         return _deserialize_list(data, klass.__args__[0])
-    #     if klass.__extra__ == dict:
-    #         return _deserialize_dict(data, klass.__args__[1])
     else:
         return deserialize_model(data, klass)
 
 
-
 def _deserialize_primitive(data, klass):
     """Deserializes to primitive type.
 
-- 
GitLab