解决swagger生成的flask代码中的AttributeError: module ‘typing‘ has no attribute ‘GenericMeta‘错误

swagger生成的flask代码存在一个bug
位置在swagger_server目录下的util.py文件中

Module 'typing' has no 'GenericMeta' member

解决办法就是把下面的代码

    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])

改为

    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])

参考:
https://github.com/zalando/connexion/issues/739#issuecomment-437398835
https://stackoverflow.com/a/50080269


2021-07-05 更新

目前codegen版本已经修复上面的问题,不需要进行上面的修改

参考:https://github.com/swagger-api/swagger-codegen-generators/pull/880

你可能感兴趣的:(Swagger/OpenAPI,Python,后端,swagger,flask,connexion,typing,genericmeta)