Python connexion not displaying Swagger UI(Python 连接不显示 Swagger UI)
问题描述
我使用 connexion 模块构建了一个基于 Python/Flask 的 REST API.这与使用 swagger.yml 文件定义 REST API 效果很好.应用程序正在运行,但是当我导航到/ui 时,我在浏览器中得到的只是:
I've built a Python/Flask based REST API using the connexion module. This working well as defining the REST API with with swagger.yml file works very well. The application is running, but when I navigate to /ui all I get in my browser is this:
我没有禁用 UI,所以我不确定发生了什么以及为什么 UI 没有显示.我的应用程序没有/static 文件夹(它只是一个 API),因此该应用程序不提供任何静态文件,不确定这是否与问题有关.
I haven't disabled the UI, so I'm not sure what's going on and why the UI isn't being displayed. My application doesn't have a /static folder (it's only an API), so the app isn't serving any static files, not sure if that's related to the problem or not.
任何关于我做错了什么的建议、指示或提示将不胜感激!
Any suggestions, pointers or hints about what I'm doing wrong would be most appreciated!
这是我的代码的简化示例:
Here is a simplified example of my code:
# 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)
提前致谢,道格
推荐答案
connexion 从 2.0.1 版本开始,里面没有捆绑 swagger-ui.您已使用以下命令显式安装它(注意引号)
connexion from 2.0.1 version onward don't have swagger-ui bundled inside it. You have install it explicitly using the below command (note the quotes)
pip install 'connexion[swagger-ui]'
安装后.swagger 将与 connexion 一起使用.在早期版本中,swagger 曾经与/ui 一起工作,在末尾添加到您的 url http(s)://host:port
Once you install it. swagger will work with connexion. In the earlier version swagger used to work with /ui added to your url at the end http(s)://host:port
但在 2.0.x 以后使用 http(s)://host:port/<basepath>/ui
But in 2.0.x onward use http(s)://host:port/<basepath>/ui
这篇关于Python 连接不显示 Swagger UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python 连接不显示 Swagger UI
基础教程推荐
- Discord.py 缺少必需的参数 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
