首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Connexion不提供Swagger UI

Connexion不提供Swagger UI
EN

Stack Overflow用户
提问于 2021-11-04 08:21:42
回答 1查看 129关注 0票数 0

我正在尝试使用Swagger/Flask/Connexion构建一个简单的应用程序接口,但是他们的GitHub上的示例不起作用,即使在按照指定的here安装Connexion Swagger-ui之后也是如此。

代码语言:javascript
复制
pip3 install 'connexion[swagger-ui]'

这是我的helloworld-api.yaml:

代码语言:javascript
复制
openapi: "3.0.0"

info:
  title: Hello World
  version: "1.0"
servers:
  - url: http://localhost:9090/swagger

paths:
  /greeting:
    get:
      summary: Generate greeting
      description: Generates a greeting message.
      operationId: hello.get_greeting
      responses:
        200:
          description: greeting response
          content:
            text/plain:
              schema:
                type: string
                example: "hello dave!"
      parameters:
        - in: query
          name: name
          required: true
          schema:
            type: string
            example: "dave"
          description: Name of the person to greet.

还有我的hello.py

代码语言:javascript
复制
#!/usr/bin/env python3

import connexion


def get_greeting(name: str) -> str:
    return f'Hello {name}'

if __name__ == '__main__':
    app = connexion.FlaskApp(__name__, specification_dir='openapi/')
    app.add_api('helloworld-api.yaml', arguments={'title': 'Hello World Example'})
    app.run(port=8080)

hello.py在根目录中,helloworld-api.yaml在一个名为openapi/的文件夹中。在浏览器中导航到0.0.0.0:8080/swagger将返回以下内容:

代码语言:javascript
复制
{
  "detail": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
  "status": 404,
  "title": "Not Found",
  "type": "about:blank"
}

我指定的get方法也是如此。有什么想法吗?我一直在为这件事碰壁。

EN

回答 1

Stack Overflow用户

发布于 2021-11-06 11:07:02

您使用了错误的修补程序,要访问Swagger UI,您必须访问0.0.0.0:8080/ui/中的{base_path}/ui/

您可以查看文档的https://connexion.readthedocs.io/en/latest/quickstart.html#the-swagger-ui-console

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69836189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档