我已经使用connexion模块构建了一个基于Python/Flask的REST API。这与使用swagger.yml文件定义REST API一样工作得很好。应用程序正在运行,但当我导航到/ui时,我在浏览器中得到的结果是:

我没有禁用UI,所以我不确定发生了什么,也不知道为什么UI没有显示。我的应用程序没有/static文件夹(它只是一个应用程序接口),所以应用程序不提供任何静态文件,不确定这是否与问题有关。
如果您对我的错误之处有任何建议、建议或提示,我将不胜感激!
以下是我的代码的简化示例:
# 3rd party libraries
from flask_cors import CORS
import connexion
def create_app(config_key, instance_config=None):
# create the connexion instance
connex_app = connexion.FlaskApp(__name__, specification_dir='./files/swagger/')
connex_app.server = 'gevent'
# get the Flask app instance
app = connex_app.app
# configure the application
app.config.from_object(config_key)
# add CORS support to application
CORS(app)
# define the API with the SWAGGER API definition YAML file
connex_app.add_api('line_controller_api.yml',
base_path='{url_prefix}'.format(url_prefix=app.config.get('URL_PREFIX', '/')),
resolver=AppResolver())
return connex_app
def production_app(instance_config=None):
app = create_app('api_config.ProductionConfig', instance_config)
return app
if __name__ == '__main__':
app = create_app('api_config.DevelopmentConfig')
port = 5001
logger.info('Line Controller API running on port %s', port)
app.run(host='0.0.0.0', port=port)提前谢谢你,道格
发布于 2019-07-26 01:43:12
从2.0.1版本开始,connexion中没有捆绑swagger-ui。您已经使用下面的命令显式地安装了它(注意引号)
pip install 'connexion[swagger-ui]'一旦你安装了它。swagger将与connexion一起工作。在较早的版本中,swagger用于在http(s)://host:port末尾添加到url中的/ui
但在2.0.x及更高版本中使用http(s)://host:port/<basepath>/ui
发布于 2020-03-03 07:18:07
我的stackoverflow声誉太低了,我无法评论上面Ashraff Ali Wahab的答案,但我刚刚发现我可以自己编辑它。我可以说,在我了解到Pablo Marin-Garcia指出的外壳语法错误后,它为我解决了这个问题。这是你在Unix/Linux中正确安装swagger-ui插件所需要的外壳语法:
pip install 'connexion[swagger-ui]'
任何匹配的引号都可以。请注意,如果没有引号,pip命令将成功运行,但它的不会按照预期安装swagger-ui组件。此外,我在这个问题上花费了很多时间,因为我是在一个虚拟环境中完成这个任务的。我还在virtualenv中搜索了带有find的swagger-ui组件,我发现安装了一些存根。因此,如果你是python的新手,或者你很匆忙,这可能很容易被错过。
最后,我决定添加一个local_requirement.txt文件,其中列出了Werzueg、connexion和“connexion SmartBear ui”的正确版本,因为它似乎是由SmartBear工具生成的Flask API代码有点过时。
发布于 2020-04-02 21:22:39
我也有同样的问题。我解决了这个问题
pip install pathlib swagger_ui_bundlehttps://stackoverflow.com/questions/46246811
复制相似问题