init commit
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import connexion
|
||||
|
||||
from openapi_server import encoder
|
||||
|
||||
|
||||
def main():
|
||||
app = connexion.App(__name__, specification_dir='./openapi/')
|
||||
app.app.json_encoder = encoder.JSONEncoder
|
||||
app.add_api('openapi.yaml',
|
||||
base_path='/api',
|
||||
arguments={'title': 'announcementService'},
|
||||
pythonic_params=True)
|
||||
|
||||
app.run(port=8080)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,51 @@
|
||||
import connexion
|
||||
from typing import Dict
|
||||
from typing import Tuple
|
||||
from typing import Union
|
||||
|
||||
from openapi_server.models.patch_notes import PatchNotes # noqa: E501
|
||||
from openapi_server import util
|
||||
|
||||
|
||||
def get_patchnotes(): # noqa: E501
|
||||
"""get_patchnotes
|
||||
|
||||
returns list of all unseen Patch notes from the user # noqa: E501
|
||||
|
||||
|
||||
:rtype: Union[List[PatchNotes], Tuple[List[PatchNotes], int], Tuple[List[PatchNotes], int, Dict[str, str]]
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def patch_note_delete(patch_id): # noqa: E501
|
||||
"""patch_note_delete
|
||||
|
||||
deletes one Patch note # noqa: E501
|
||||
|
||||
:param patch_id:
|
||||
:type patch_id: str
|
||||
:type patch_id: str
|
||||
|
||||
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def post_patchnotes(body=None): # noqa: E501
|
||||
"""post_patchnotes
|
||||
|
||||
creates new Patch notes # noqa: E501
|
||||
|
||||
:param patch_notes:
|
||||
:type patch_notes: dict | bytes
|
||||
|
||||
:rtype: Union[List[PatchNotes], Tuple[List[PatchNotes], int], Tuple[List[PatchNotes], int, Dict[str, str]]
|
||||
"""
|
||||
patch_notes = body
|
||||
with conn.cursor() as cur:
|
||||
player_name = player_post_request.name
|
||||
player_id = uuid.uuid4()
|
||||
cur.execute(f"INSERT INTO player VALUES ('{player_id}','{player_name}');")
|
||||
conn.commit() # noqa: E501
|
||||
return 'do some magic!'
|
||||
@@ -0,0 +1,2 @@
|
||||
from typing import List
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
from connexion.apps.flask_app import FlaskJSONEncoder
|
||||
|
||||
from openapi_server.models.base_model import Model
|
||||
|
||||
|
||||
class JSONEncoder(FlaskJSONEncoder):
|
||||
include_nulls = False
|
||||
|
||||
def default(self, o):
|
||||
if isinstance(o, Model):
|
||||
dikt = {}
|
||||
for attr in o.openapi_types:
|
||||
value = getattr(o, attr)
|
||||
if value is None and not self.include_nulls:
|
||||
continue
|
||||
attr = o.attribute_map[attr]
|
||||
dikt[attr] = value
|
||||
return dikt
|
||||
return FlaskJSONEncoder.default(self, o)
|
||||
@@ -0,0 +1,4 @@
|
||||
# flake8: noqa
|
||||
# import models into model package
|
||||
from openapi_server.models.patch_notes import PatchNotes
|
||||
from openapi_server.models.user import User
|
||||
@@ -0,0 +1,68 @@
|
||||
import pprint
|
||||
|
||||
import typing
|
||||
|
||||
from openapi_server import util
|
||||
|
||||
T = typing.TypeVar('T')
|
||||
|
||||
|
||||
class Model:
|
||||
# openapiTypes: The key is attribute name and the
|
||||
# value is attribute type.
|
||||
openapi_types: typing.Dict[str, type] = {}
|
||||
|
||||
# attributeMap: The key is attribute name and the
|
||||
# value is json key in definition.
|
||||
attribute_map: typing.Dict[str, str] = {}
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls: typing.Type[T], dikt) -> T:
|
||||
"""Returns the dict as a model"""
|
||||
return util.deserialize_model(dikt, cls)
|
||||
|
||||
def to_dict(self):
|
||||
"""Returns the model properties as a dict
|
||||
|
||||
:rtype: dict
|
||||
"""
|
||||
result = {}
|
||||
|
||||
for attr in self.openapi_types:
|
||||
value = getattr(self, attr)
|
||||
if isinstance(value, list):
|
||||
result[attr] = list(map(
|
||||
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
|
||||
value
|
||||
))
|
||||
elif hasattr(value, "to_dict"):
|
||||
result[attr] = value.to_dict()
|
||||
elif isinstance(value, dict):
|
||||
result[attr] = dict(map(
|
||||
lambda item: (item[0], item[1].to_dict())
|
||||
if hasattr(item[1], "to_dict") else item,
|
||||
value.items()
|
||||
))
|
||||
else:
|
||||
result[attr] = value
|
||||
|
||||
return result
|
||||
|
||||
def to_str(self):
|
||||
"""Returns the string representation of the model
|
||||
|
||||
:rtype: str
|
||||
"""
|
||||
return pprint.pformat(self.to_dict())
|
||||
|
||||
def __repr__(self):
|
||||
"""For `print` and `pprint`"""
|
||||
return self.to_str()
|
||||
|
||||
def __eq__(self, other):
|
||||
"""Returns true if both objects are equal"""
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
"""Returns true if both objects are not equal"""
|
||||
return not self == other
|
||||
@@ -0,0 +1,139 @@
|
||||
from datetime import date, datetime # noqa: F401
|
||||
|
||||
from typing import List, Dict # noqa: F401
|
||||
|
||||
from openapi_server.models.base_model import Model
|
||||
from openapi_server import util
|
||||
|
||||
|
||||
class PatchNotes(Model):
|
||||
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
def __init__(self, patch_id=None, title=None, changes=None, _date=None): # noqa: E501
|
||||
"""PatchNotes - a model defined in OpenAPI
|
||||
|
||||
:param patch_id: The patch_id of this PatchNotes. # noqa: E501
|
||||
:type patch_id: str
|
||||
:param title: The title of this PatchNotes. # noqa: E501
|
||||
:type title: str
|
||||
:param changes: The changes of this PatchNotes. # noqa: E501
|
||||
:type changes: str
|
||||
:param _date: The _date of this PatchNotes. # noqa: E501
|
||||
:type _date: str
|
||||
"""
|
||||
self.openapi_types = {
|
||||
'patch_id': str,
|
||||
'title': str,
|
||||
'changes': str,
|
||||
'_date': str
|
||||
}
|
||||
|
||||
self.attribute_map = {
|
||||
'patch_id': 'patchID',
|
||||
'title': 'title',
|
||||
'changes': 'changes',
|
||||
'_date': 'date'
|
||||
}
|
||||
|
||||
self._patch_id = patch_id
|
||||
self._title = title
|
||||
self._changes = changes
|
||||
self.__date = _date
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, dikt) -> 'PatchNotes':
|
||||
"""Returns the dict as a model
|
||||
|
||||
:param dikt: A dict.
|
||||
:type: dict
|
||||
:return: The patch_notes of this PatchNotes. # noqa: E501
|
||||
:rtype: PatchNotes
|
||||
"""
|
||||
return util.deserialize_model(dikt, cls)
|
||||
|
||||
@property
|
||||
def patch_id(self) -> str:
|
||||
"""Gets the patch_id of this PatchNotes.
|
||||
|
||||
|
||||
:return: The patch_id of this PatchNotes.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._patch_id
|
||||
|
||||
@patch_id.setter
|
||||
def patch_id(self, patch_id: str):
|
||||
"""Sets the patch_id of this PatchNotes.
|
||||
|
||||
|
||||
:param patch_id: The patch_id of this PatchNotes.
|
||||
:type patch_id: str
|
||||
"""
|
||||
|
||||
self._patch_id = patch_id
|
||||
|
||||
@property
|
||||
def title(self) -> str:
|
||||
"""Gets the title of this PatchNotes.
|
||||
|
||||
|
||||
:return: The title of this PatchNotes.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._title
|
||||
|
||||
@title.setter
|
||||
def title(self, title: str):
|
||||
"""Sets the title of this PatchNotes.
|
||||
|
||||
|
||||
:param title: The title of this PatchNotes.
|
||||
:type title: str
|
||||
"""
|
||||
|
||||
self._title = title
|
||||
|
||||
@property
|
||||
def changes(self) -> str:
|
||||
"""Gets the changes of this PatchNotes.
|
||||
|
||||
|
||||
:return: The changes of this PatchNotes.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._changes
|
||||
|
||||
@changes.setter
|
||||
def changes(self, changes: str):
|
||||
"""Sets the changes of this PatchNotes.
|
||||
|
||||
|
||||
:param changes: The changes of this PatchNotes.
|
||||
:type changes: str
|
||||
"""
|
||||
|
||||
self._changes = changes
|
||||
|
||||
@property
|
||||
def _date(self) -> str:
|
||||
"""Gets the _date of this PatchNotes.
|
||||
|
||||
|
||||
:return: The _date of this PatchNotes.
|
||||
:rtype: str
|
||||
"""
|
||||
return self.__date
|
||||
|
||||
@_date.setter
|
||||
def _date(self, _date: str):
|
||||
"""Sets the _date of this PatchNotes.
|
||||
|
||||
|
||||
:param _date: The _date of this PatchNotes.
|
||||
:type _date: str
|
||||
"""
|
||||
|
||||
self.__date = _date
|
||||
@@ -0,0 +1,61 @@
|
||||
from datetime import date, datetime # noqa: F401
|
||||
|
||||
from typing import List, Dict # noqa: F401
|
||||
|
||||
from openapi_server.models.base_model import Model
|
||||
from openapi_server import util
|
||||
|
||||
|
||||
class User(Model):
|
||||
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
def __init__(self, last_note_checked=None): # noqa: E501
|
||||
"""User - a model defined in OpenAPI
|
||||
|
||||
:param last_note_checked: The last_note_checked of this User. # noqa: E501
|
||||
:type last_note_checked: str
|
||||
"""
|
||||
self.openapi_types = {
|
||||
'last_note_checked': str
|
||||
}
|
||||
|
||||
self.attribute_map = {
|
||||
'last_note_checked': 'lastNoteChecked'
|
||||
}
|
||||
|
||||
self._last_note_checked = last_note_checked
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, dikt) -> 'User':
|
||||
"""Returns the dict as a model
|
||||
|
||||
:param dikt: A dict.
|
||||
:type: dict
|
||||
:return: The user of this User. # noqa: E501
|
||||
:rtype: User
|
||||
"""
|
||||
return util.deserialize_model(dikt, cls)
|
||||
|
||||
@property
|
||||
def last_note_checked(self) -> str:
|
||||
"""Gets the last_note_checked of this User.
|
||||
|
||||
|
||||
:return: The last_note_checked of this User.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._last_note_checked
|
||||
|
||||
@last_note_checked.setter
|
||||
def last_note_checked(self, last_note_checked: str):
|
||||
"""Sets the last_note_checked of this User.
|
||||
|
||||
|
||||
:param last_note_checked: The last_note_checked of this User.
|
||||
:type last_note_checked: str
|
||||
"""
|
||||
|
||||
self._last_note_checked = last_note_checked
|
||||
@@ -0,0 +1,102 @@
|
||||
openapi: 3.0.3
|
||||
info:
|
||||
description: Announcing patchnotes for KanzleiApp
|
||||
title: announcementService
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: /
|
||||
paths:
|
||||
/patchnotes:
|
||||
get:
|
||||
description: returns list of all unseen Patch notes from the user
|
||||
operationId: get_patchnotes
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/components/schemas/patch_notes'
|
||||
type: array
|
||||
description: returns list of all unseen Patch notes from the user
|
||||
"404":
|
||||
description: no Patch notes found
|
||||
"500":
|
||||
description: "Internal Server error, Failed to get Patch Notes"
|
||||
tags:
|
||||
- Patchnotes
|
||||
x-openapi-router-controller: openapi_server.controllers.patchnotes_controller
|
||||
post:
|
||||
description: creates new Patch notes
|
||||
operationId: post_patchnotes
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/patch_notes'
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/components/schemas/patch_notes'
|
||||
type: array
|
||||
description: game created
|
||||
tags:
|
||||
- Patchnotes
|
||||
x-openapi-router-controller: openapi_server.controllers.patchnotes_controller
|
||||
/patchnotes/{patchID}:
|
||||
delete:
|
||||
description: deletes one Patch note
|
||||
operationId: patch_note_delete
|
||||
parameters:
|
||||
- explode: false
|
||||
in: path
|
||||
name: patchID
|
||||
required: true
|
||||
schema:
|
||||
format: uuid
|
||||
type: string
|
||||
style: simple
|
||||
responses:
|
||||
"200":
|
||||
description: patch successfully deleted
|
||||
"404":
|
||||
description: patch not found
|
||||
"500":
|
||||
description: "Internal Server Error, Patch not deleted"
|
||||
tags:
|
||||
- Patchnotes
|
||||
x-openapi-router-controller: openapi_server.controllers.patchnotes_controller
|
||||
components:
|
||||
schemas:
|
||||
patch_notes:
|
||||
example:
|
||||
patchID: 29e80bcc-5981-4a52-99e1-373442dea9b9
|
||||
title: Patch note 1
|
||||
changes: changes
|
||||
date: date
|
||||
properties:
|
||||
patchID:
|
||||
format: uuid
|
||||
title: patchID
|
||||
type: string
|
||||
title:
|
||||
title: title
|
||||
type: string
|
||||
changes:
|
||||
title: changes
|
||||
type: string
|
||||
date:
|
||||
title: date
|
||||
type: string
|
||||
title: patch_notes
|
||||
user:
|
||||
example:
|
||||
lastNoteChecked: f00fa08d-0cd8-4c05-9409-5e75aa2d4f68
|
||||
properties:
|
||||
lastNoteChecked:
|
||||
format: uuid
|
||||
title: lastNoteChecked
|
||||
type: string
|
||||
@@ -0,0 +1,16 @@
|
||||
import logging
|
||||
|
||||
import connexion
|
||||
from flask_testing import TestCase
|
||||
|
||||
from openapi_server.encoder import JSONEncoder
|
||||
|
||||
|
||||
class BaseTestCase(TestCase):
|
||||
|
||||
def create_app(self):
|
||||
logging.getLogger('connexion.operation').setLevel('ERROR')
|
||||
app = connexion.App(__name__, specification_dir='../openapi/')
|
||||
app.app.json_encoder = JSONEncoder
|
||||
app.add_api('openapi.yaml', pythonic_params=True)
|
||||
return app.app
|
||||
@@ -0,0 +1,62 @@
|
||||
import unittest
|
||||
|
||||
from flask import json
|
||||
|
||||
from openapi_server.models.patch_notes import PatchNotes # noqa: E501
|
||||
from openapi_server.test import BaseTestCase
|
||||
|
||||
|
||||
class TestDefaultController(BaseTestCase):
|
||||
"""DefaultController integration test stubs"""
|
||||
|
||||
def test_get_patchnotes(self):
|
||||
"""Test case for get_patchnotes
|
||||
|
||||
|
||||
"""
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
response = self.client.open(
|
||||
'/patchnotes',
|
||||
method='GET',
|
||||
headers=headers)
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
def test_patch_note_delete(self):
|
||||
"""Test case for patch_note_delete
|
||||
|
||||
|
||||
"""
|
||||
headers = {
|
||||
}
|
||||
response = self.client.open(
|
||||
'/patchnotes/{patch_id}'.format(patch_id='patch_id_example'),
|
||||
method='DELETE',
|
||||
headers=headers)
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
def test_post_patchnotes(self):
|
||||
"""Test case for post_patchnotes
|
||||
|
||||
|
||||
"""
|
||||
patch_notes = openapi_server.PatchNotes()
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
response = self.client.open(
|
||||
'/patchnotes',
|
||||
method='POST',
|
||||
headers=headers,
|
||||
data=json.dumps(patch_notes),
|
||||
content_type='application/json')
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,63 @@
|
||||
import unittest
|
||||
|
||||
from flask import json
|
||||
|
||||
import openapi_server
|
||||
from openapi_server.models.patch_notes import PatchNotes # noqa: E501
|
||||
from openapi_server.test import BaseTestCase
|
||||
|
||||
|
||||
class TestPatchnotesController(BaseTestCase):
|
||||
"""PatchnotesController integration test stubs"""
|
||||
|
||||
def test_get_patchnotes(self):
|
||||
"""Test case for get_patchnotes
|
||||
|
||||
|
||||
"""
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
response = self.client.open(
|
||||
'/patchnotes',
|
||||
method='GET',
|
||||
headers=headers)
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
def test_patch_note_delete(self):
|
||||
"""Test case for patch_note_delete
|
||||
|
||||
|
||||
"""
|
||||
headers = {
|
||||
}
|
||||
response = self.client.open(
|
||||
'/patchnotes/{patch_id}'.format(patch_id='patch_id_example'),
|
||||
method='DELETE',
|
||||
headers=headers)
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
def test_post_patchnotes(self):
|
||||
"""Test case for post_patchnotes
|
||||
|
||||
|
||||
"""
|
||||
patch_notes = openapi_server.PatchNotes()
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
response = self.client.open(
|
||||
'/patchnotes',
|
||||
method='POST',
|
||||
headers=headers,
|
||||
data=json.dumps(patch_notes),
|
||||
content_type='application/json')
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,30 @@
|
||||
import sys
|
||||
|
||||
if sys.version_info < (3, 7):
|
||||
import typing
|
||||
|
||||
def is_generic(klass):
|
||||
""" Determine whether klass is a generic class """
|
||||
return type(klass) == typing.GenericMeta
|
||||
|
||||
def is_dict(klass):
|
||||
""" Determine whether klass is a Dict """
|
||||
return klass.__extra__ == dict
|
||||
|
||||
def is_list(klass):
|
||||
""" Determine whether klass is a List """
|
||||
return klass.__extra__ == list
|
||||
|
||||
else:
|
||||
|
||||
def is_generic(klass):
|
||||
""" Determine whether klass is a generic class """
|
||||
return hasattr(klass, '__origin__')
|
||||
|
||||
def is_dict(klass):
|
||||
""" Determine whether klass is a Dict """
|
||||
return klass.__origin__ == dict
|
||||
|
||||
def is_list(klass):
|
||||
""" Determine whether klass is a List """
|
||||
return klass.__origin__ == list
|
||||
@@ -0,0 +1,147 @@
|
||||
import datetime
|
||||
|
||||
import typing
|
||||
from openapi_server import typing_utils
|
||||
|
||||
|
||||
def _deserialize(data, klass):
|
||||
"""Deserializes dict, list, str into an object.
|
||||
|
||||
:param data: dict, list or str.
|
||||
:param klass: class literal, or string of class name.
|
||||
|
||||
:return: object.
|
||||
"""
|
||||
if data is None:
|
||||
return None
|
||||
|
||||
if klass in (int, float, str, bool, bytearray):
|
||||
return _deserialize_primitive(data, klass)
|
||||
elif klass == object:
|
||||
return _deserialize_object(data)
|
||||
elif klass == datetime.date:
|
||||
return deserialize_date(data)
|
||||
elif klass == datetime.datetime:
|
||||
return deserialize_datetime(data)
|
||||
elif typing_utils.is_generic(klass):
|
||||
if typing_utils.is_list(klass):
|
||||
return _deserialize_list(data, klass.__args__[0])
|
||||
if typing_utils.is_dict(klass):
|
||||
return _deserialize_dict(data, klass.__args__[1])
|
||||
else:
|
||||
return deserialize_model(data, klass)
|
||||
|
||||
|
||||
def _deserialize_primitive(data, klass):
|
||||
"""Deserializes to primitive type.
|
||||
|
||||
:param data: data to deserialize.
|
||||
:param klass: class literal.
|
||||
|
||||
:return: int, long, float, str, bool.
|
||||
:rtype: int | long | float | str | bool
|
||||
"""
|
||||
try:
|
||||
value = klass(data)
|
||||
except UnicodeEncodeError:
|
||||
value = data
|
||||
except TypeError:
|
||||
value = data
|
||||
return value
|
||||
|
||||
|
||||
def _deserialize_object(value):
|
||||
"""Return an original value.
|
||||
|
||||
:return: object.
|
||||
"""
|
||||
return value
|
||||
|
||||
|
||||
def deserialize_date(string):
|
||||
"""Deserializes string to date.
|
||||
|
||||
:param string: str.
|
||||
:type string: str
|
||||
:return: date.
|
||||
:rtype: date
|
||||
"""
|
||||
if string is None:
|
||||
return None
|
||||
|
||||
try:
|
||||
from dateutil.parser import parse
|
||||
return parse(string).date()
|
||||
except ImportError:
|
||||
return string
|
||||
|
||||
|
||||
def deserialize_datetime(string):
|
||||
"""Deserializes string to datetime.
|
||||
|
||||
The string should be in iso8601 datetime format.
|
||||
|
||||
:param string: str.
|
||||
:type string: str
|
||||
:return: datetime.
|
||||
:rtype: datetime
|
||||
"""
|
||||
if string is None:
|
||||
return None
|
||||
|
||||
try:
|
||||
from dateutil.parser import parse
|
||||
return parse(string)
|
||||
except ImportError:
|
||||
return string
|
||||
|
||||
|
||||
def deserialize_model(data, klass):
|
||||
"""Deserializes list or dict to model.
|
||||
|
||||
:param data: dict, list.
|
||||
:type data: dict | list
|
||||
:param klass: class literal.
|
||||
:return: model object.
|
||||
"""
|
||||
instance = klass()
|
||||
|
||||
if not instance.openapi_types:
|
||||
return data
|
||||
|
||||
for attr, attr_type in instance.openapi_types.items():
|
||||
if data is not None \
|
||||
and instance.attribute_map[attr] in data \
|
||||
and isinstance(data, (list, dict)):
|
||||
value = data[instance.attribute_map[attr]]
|
||||
setattr(instance, attr, _deserialize(value, attr_type))
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
def _deserialize_list(data, boxed_type):
|
||||
"""Deserializes a list and its elements.
|
||||
|
||||
:param data: list to deserialize.
|
||||
:type data: list
|
||||
:param boxed_type: class literal.
|
||||
|
||||
:return: deserialized list.
|
||||
:rtype: list
|
||||
"""
|
||||
return [_deserialize(sub_data, boxed_type)
|
||||
for sub_data in data]
|
||||
|
||||
|
||||
def _deserialize_dict(data, boxed_type):
|
||||
"""Deserializes a dict and its elements.
|
||||
|
||||
:param data: dict to deserialize.
|
||||
:type data: dict
|
||||
:param boxed_type: class literal.
|
||||
|
||||
:return: deserialized dict.
|
||||
:rtype: dict
|
||||
"""
|
||||
return {k: _deserialize(v, boxed_type)
|
||||
for k, v in data.items() }
|
||||
Reference in New Issue
Block a user