连接:flask api throwing 无法解析 operationId“people.welcome”!导入错误是“没有名为‘people’的模块”

问题描述 投票:0回答:1

这是我的项目结构:

这是我的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 提供绝对路径/相对路径,但仍然没有任何效果

python-3.x flask flask-restful connexion
1个回答
0
投票

@connexion 2.14.1

Connexion 不能很好地处理

__init__.py
。这些步骤应该可以解决它:

  1. 删除您的
    __init__.py
    (无论如何,Connexion 都会在
    operationId
    内解决包裹);
  2. Connexion 为您创建 Flask
    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!"
© www.soinside.com 2019 - 2024. All rights reserved.