这是我的app.py
from flask import Flask
import connexion
app = connexion.App(__name__, specification_dir="./")
app.add_api("swagger.yaml")
这是我的人.py
from .app import app
def welcome():
return "Hello World!"
这是我的 init.py
from .app import app
from .people import welcome
这是我的 swagger.yaml 文件
openapi: 3.0.0
info:
title: "RP Flask REST API"
description: "An API about people and notes"
version: "1.0.0"
servers:
- url: "/api"
paths:
/hello:
get:
operationId: people.welcome
tags:
- "People"
summary: "Read the list of people"
responses:
"200":
description: "Successfully read people list"
运行烧瓶应用程序时出现以下错误:
File "C:\Users\PycharmProjects\connexionTest\venv\lib\site-packages\connexion\resolver.py", line 71, in resolve_function_from_operation_id
raise ResolverError(msg, sys.exc_info())
connexion.exceptions.ResolverError: <ResolverError: Cannot resolve operationId "people.welcome"! Import error was "No module named 'people'">
我试图给操作 id 提供绝对路径/相对路径,但仍然没有任何效果
Connexion 不能很好地处理
__init__.py
。这些步骤应该可以解决它:
__init__.py
(无论如何,Connexion 都会在 operationId
内解决包裹);app
,无需直接导入 Flask。你的
app.py
应该是这样的:
import connexion
app = connexion.App(__name__, specification_dir="./")
app.add_api("swagger.yaml")
app = app.app
而您的
people.py
目前不需要任何导入:
def welcome():
return "Hello World!"