我正在使用python烧瓶应用程序和API文档使用flasgger。当我在本地运行我的烧瓶应用程序http://localhost:8086/swagger/时,我得到了正确的用户界面。
现在,我们已经使用Nginx前端服务部署了应用程序。当我们调用已部署的链接http://localhost:8086/api/core/swagger/时,我们会看到一个空白白页,页面右上半部分是Powered by Flasgger 0.9.5。
在中,我得到了这个错误。
Uncaught ReferenceError: SwaggerUIBundle is not defined
at window.onload ((index):72:16)我知道这可能是flasgger试图加载CSS文件或其他资源时遇到的一些问题,而且它没有正确地呈现。因为一条路
在我对swagger的配置过程中,我对它具有以下配置函数。
def configure_swagger(app):
swagger_config = {
"headers": [],
"specs": [
{
"endpoint": "apispec_1",
"route": "apispec_1.json",
"rule_filter": lambda rule: True, # all in
"model_filter": lambda tag: True, # all in
}
],
"static_url_path": "/flasgger_static",
"swagger_ui": True,
"specs_route": "/swagger/",
'openapi': '3.0.3'
}
swagger_template = {
'components': {
'securitySchemes': {
'bearerAuth': {
'type': 'http',
'scheme': 'bearer',
'bearerFormat': 'JWT'
}
},
'security': [{
'bearerAuth': []
}]
}
}
swagger = Swagger(app, config=swagger_config, template=swagger_template)api.py中的所有其他端点都遵循这个体系结构。
@api.route("/hello")
@swag_from("Swagger/hello.yml")
# @log_writer
def hello():
projects = {"id": 1, "title": "Hello"}
return projects["title"]
@api.route("/healtz")
@swag_from("Swagger/healtz.yml")
def healtz():
return_dict = {"App Version": "1.0.0", "Status": "Healthy"}
return return_dict我的healtz.yaml文件示例:
summary: "Upload"
description: "Give the info in json"
consumes:
- "application/json"
produces:
- "application/json"
responses:
405:
description: "Invalid input"
security:
- bearerAuth: []该YAML文件位于项目中,其中有一个名为Swagger的目录。
我已经做了以下的回答,但没有得到答案。
对于部署,我们使用EKS服务,在这里我们有我们的容器。
为什么会发生这个问题?有人能帮我处理密码吗?
发布于 2022-03-28 22:32:37
之所以会发生这种情况,是因为当NGINX将URL转发到您的Flask应用程序时,您的URL正在被NGINX重写。因此,当您的浏览器访问http://your-domain/api/core/swagger/时,NGINX将转发到您的Flask应用程序作为http://flask-app/swagger/。尽管如此,Flasgger并不知道这一点,而且在它的代码中,它将URL硬编码为http://your-domain/swagger/,这显然不存在,因为NGINX不将/swagger路由到您的/swagger应用程序。
一个潜在的解决方案可以看到这里。您不用查询Swagger库的本地版本,而是使用外部CDN托管的JS文件来加载swagger网页。
https://stackoverflow.com/questions/70879832
复制相似问题