从 Swagger 编辑器生成 Swagger 服务器 (Python Flask) 时出错

Error generating Swagger server (Python Flask) from Swagger editor

我使用 Swagger 编辑器手动生成我的 Swagger 规范文件并为 Python Flask 服务器生成文件。按照 README 我安装了 connexion,但是当我 运行 python app.py 我得到错误: ValueError:需要超过 1 个值才能解包。有什么想法吗?

下面的完整堆栈跟踪:

No handlers could be found for logger "connexion.api"
Traceback (most recent call last):
  File "app.py", line 5, in <module>
    app.add_api('swagger.yaml')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/app.py", line 144, in add_api
    debug=self.debug)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/api.py", line 127, in __init__
    self.add_paths()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/api.py", line 198, in add_paths
    six.reraise(*sys.exc_info())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/api.py", line 187, in add_paths
    self.add_operation(method, path, endpoint, path_parameters)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/api.py", line 160, in add_operation
    resolver=self.resolver)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/operation.py", line 168, in __init__
    resolution = resolver.resolve(self)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/resolver.py", line 50, in resolve
    return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/resolver.py", line 71, in resolve_function_from_operation_id
    return self.function_resolver(operation_id)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/connexion/utils.py", line 106, in get_function_from_name
    module_name, attr_path1 = module_name.rsplit('.', 1)
ValueError: need more than 1 value to unpack

我运行也喜欢这个。据我所知,Swagger 生成的代码似乎假设您使用的是 Python 3。虽然 connexion 支持 Python 2.7 和 3.4+,但它确实需要一个 __init__.py 文件生成了 python-flask-server/ 基目录以及 controllers/ 子目录,用于 Python 2.7(在 Python 3.3 中引入了隐式命名空间包)。如果您在生成代码后创建这 2 个空文件,应该可以正常工作。如果 Swagger 生成器想要支持 Python 2.7(因为连接允许),它也只需要提供这些文件。