generated from HIRO-MicroDataCenters-BV/template-web-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Piao
committed
Jul 1, 2024
1 parent
7885474
commit c816ef1
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |