nginx – 如何修改swagger.json的默认文件路径?
作者:互联网
我已经创建了引用https://github.com/nginxinc/NGINX-Demos/tree/master/consul-template-demo的Ngnix-Consul Docker设置.
并创造了许多微服务.因此,只有在添加服务名称后,才能访问所有微服务.
http://example.com/service_name/get_data
一切正常,然后我想为所有微服务添加招摇,所以尝试使用下面的代码片段
我可以通过使用访问swagger ui
http://example.com/service_name/ui
但问题是我无法在该ui中加载swagger.json,因为它试图在下面的url上访问swagger.json
http://example.com/swagger.json
但是json文件已打开
http://example.com/service_name/swagger.json
如何更改swagger.json的默认路径?
微服务中的应用程序是在python-flask中创建的
我试过下面的片段
swagger: "2.0"
info:
description: "Add service"
version: "1.0.0"
title: "Add Service"
contact:
email: "abc@efg.com"
license:
name: "s1.0"
url: "http://sample.com"
host: "abc.efg.com"
tags:
- name: "add service"
description: "service"
- name: "delete service"
description: "data"
schemes:
- "http"
paths:
/service_name/get_data:
甚至我试图在swagger.yaml文件中添加basePath
然后它甚至没有打开swaggerui
swagger: "2.0"
info:
description: "Add service"
version: "1.0.0"
title: "Add Service"
contact:
email: "abc@efg.com"
license:
name: "s1.0"
url: "http://sample.com"
host: "abc.efg.com"
basePath: "service_name"
tags:
- name: "add service"
description: "service"
- name: "delete service"
description: "data"
schemes:
- "http"
paths:
/get_data:
更新:
from flask import Flask
import connexion
app = Flask(__name__)
app = connexion.App(__name__)
app.add_api('swagger.yaml')
//apis
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8090, debug=True)
解决方法:
如果文件swagger.json在NGINX配置中是静态的,你可以像这样建立别名规则:
location ^~ /swagger.json {
alias /path_to/swagger.json;
}
标签:nginx,swagger,swagger-ui,consul,swagger-2-0 来源: https://codeday.me/bug/20190710/1425525.html