我使用 connexion 模块构建了一个基于 Python/Flask 的 REST API。这与使用 swagger.yml 文件定义 REST API 一样效果很好。该应用程序正在运行,但是当我导航到<my-app-url>/ui
我在浏览器中得到的只是:
我没有禁用用户界面,所以我不确定发生了什么以及为什么不显示用户界面。我的应用程序没有 /static 文件夹(它只是一个 API),因此该应用程序不提供任何静态文件,不确定这是否与问题相关。
我究竟做错了什么?
这是我的代码的简化示例:
# 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)
连接从2.0.1版本开始没有swagger-ui捆绑在里面。您已使用以下命令显式安装它(注意引号)
pip install 'connexion[swagger-ui]'
一旦你安装了它。 swagger 将与连接一起工作。在早期版本中,swagger 用于将 /ui 添加到末尾的 URL 中http(s)://host:port
但在2.0.x以后使用http(s)://host:port/<basepath>/ui
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)