所以我使用开式发电机来生成一个烧瓶服务器来服务我的api。
生成服务器、运行服务器和在浏览器中查看端点都没有问题。但是,当我从发出get请求时,我会得到一个CORS错误。
我试了几样东西让CORS。
我尝试在我的.yaml中将头添加到我的端点。
/pipelines:
get:
summary: 'Returns a list of pipelines.'
operationId: get_pipelines
responses:
'200':
description: 'A JSON array of pipelines'
content:
application/json:
schema:
$ref: '#/components/schemas/Pipeline'
headers:
Access-Control-Allow-Origin: '*'
default:
description: Unexpected error
content:
'application/json':
schema:
$ref: '#/components/schemas/ErrorMessage'
当我尝试通过.yaml添加标头并重新生成服务器模块时,我会得到以下错误:
-attribute paths.'/pipelines'(get).responses.200.Access-Control-Allow-Origin is not of type `object
我还尝试在服务器模块的flask_cors主.py中安装和导入。
#!/usr/bin/env python3
import connexion
from openapi_server import encoder
from flask_cors import CORS
def main():
app = connexion.App(__name__, specification_dir='./openapi/')
CORS(app.app)
app.app.json_encoder = encoder.JSONEncoder
app.add_api('openapi.yaml',
arguments={'title': 'ICDR API'},
pythonic_params=True)
app.run(port=5050)
if __name__ == '__main__':
main()
我把这两个都试过了。这些修正是我在swagger-codegen petstore.yaml示例和连接子文档中找到的。
然而,正如我所说的,我正在使用openapi生成器,所以它与其他任何一种工具都有一点不同,但我在找到有关如何正确设置这些工具的信息时遇到了很多困难。以前有没有人和openapi生成器合作过谁能帮我?
https://stackoverflow.com/questions/58921020
复制