diff --git a/client/openapi_server/__init__.py b/client/openapi_server/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/client/openapi_server/encoder.py b/client/openapi_server/encoder.py new file mode 100644 index 0000000..8682003 --- /dev/null +++ b/client/openapi_server/encoder.py @@ -0,0 +1,19 @@ +from json import JSONEncoder + +from openapi_server.models.base_model import Model + + +class JSONEncoder(JSONEncoder): + 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 JSONEncoder.default(self, o) diff --git a/client/openapi_server/typing_utils.py b/client/openapi_server/typing_utils.py new file mode 100644 index 0000000..74e3c91 --- /dev/null +++ b/client/openapi_server/typing_utils.py @@ -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