Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Piao committed Jul 1, 2024
1 parent 7885474 commit c816ef1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Empty file.
19 changes: 19 additions & 0 deletions client/openapi_server/encoder.py
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 30 additions & 0 deletions client/openapi_server/typing_utils.py
Original file line number Diff line number Diff line change
@@ -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 comments on commit c816ef1

Please sign in to comment.