I built my api with flask, connexion and swagger UI
. I defined my apispec with openapi. I created swagger python server stub from swagger editor where you can find sample project on github. when I deseialize request JSON data for validation, util.py
will be used, but I have following error:
erorr
Traceback (most recent call last):
File "C:\Users\kim\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\kim\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\kim\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\kim\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\kim\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\kim\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\kim\AppData\Local\Programs\Python\Python37\lib\site-packages\connexion\decorators\decorator.py", line 48, in wrapper
response = function(request)
File "C:\Users\kim\AppData\Local\Programs\Python\Python37\lib\site-packages\connexion\decorators\security.py", line 327, in wrapper
return function(request)
File "C:\Users\kim\AppData\Local\Programs\Python\Python37\lib\site-packages\connexion\decorators\uri_parsing.py", line 144, in wrapper
response = function(request)
File "C:\Users\kim\AppData\Local\Programs\Python\Python37\lib\site-packages\connexion\decorators\validation.py", line 184, in wrapper
response = function(request)
File "C:\Users\kim\AppData\Local\Programs\Python\Python37\lib\site-packages\connexion\decorators\parameter.py", line 121, in wrapper
return function(**kwargs)
File "C:\Users\kim\codegen_server\openapi_server\controllers\default_controller.py", line 74, in immunomatch_ed_post
body = ImmunomatchEdInput.from_dict(connexion.request.get_json()) # noqa: E501
File "C:\Users\kim\codegen_server\openapi_server\models\immunomatch_ed_input.py", line 62, in from_dict
return util.deserialize_model(dikt, cls)
File "C:\Users\kim\codegen_server\openapi_server\util.py", line 111, in deserialize_model
setattr(instance, attr, _deserialize(value, attr_type))
File "C:\Users\kim\codegen_server\openapi_server\util.py", line 26, in _deserialize
elif type(klass) == typing.GenericMeta:
AttributeError: module 'typing' has no attribute 'GenericMeta'
error message said typing
module has no attribute 'GenericMeta', which I don't understand why. can anyone point me out why this error happened? Is that because of typing
module version error or what? any possible thought to get rid of this error? any thought? thanks
update: code that I tried:
import six
import typing
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 six.integer_types or klass in (float, str, bool):
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 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)
error said this line elif type(klass) == typing.GenericMeta:
is not passed. any idea?
you might change your code to something like this:
elif hasattr(klass, '__origin__'):
if klass.__origin__ == list:
return _deserialize_list(data, klass.__args__[0])
if klass.__origin__ == dict:
return _deserialize_dict(data, klass.__args__[1])