本地生成的Swagger UI,但在Heroku上找不到页面

时间:2019-05-16 12:50:39

标签: python-3.x heroku swagger

我已经使用Python和Flask构建了RESTful API,并将其部署在Heroku上。该API可以正常运行,但是我无法访问我的摇摇欲坠的UI页面,但是出现404错误,但是当我在本地运行它时,我没有遇到问题。

我看到很多帖子说问题可能来自HTTPS连接,所以我在swagger.yml文件中指定了不同的方案,但是它没有任何改变。

swagger: "2.0"
info:
  description: my swagger file
  version: "1.0.0"
  title: my title
consumes:
  - application/json
produces:
  - application/json

host : myapi.herokuapp.com
basePath: /api
schemes: [http, https]

paths:
  /spread:
    get:
      operationId: spread.read_all
      tags:
        - Spread
      summary: Read the file containing all calculated values
      description: Read the file containing all calculated values
      parameters:
        - name: length
          in: query
          type: integer
          description: Number of people to get from people
          required: false
        - name: offset
          in: query
          type: integer
          description: Offset from beginning of list where to start gathering people
          required: false
      responses:
        200:
          description: description
          schema:
            type: array
            items:
              properties:
                exp_spread:
                  type: string

这是我的requirements.txt

flask
pandas
gunicorn
connexion

我想像在本地一样通过输入https://myapi.herokuapp.com/api/ui来访问我的招摇文档页面。

1 个答案:

答案 0 :(得分:0)

更新您的requirements.txt以依赖

connexion[swagger-ui]

而不是仅仅connexion,然后重新部署。 The UI isn't installed by default

  

可通过pip extras获得API的Swagger UI。您可以使用pip install connexion[swagger-ui]安装它。它将在{base_path}/ui/处提供,其中base_path是API的基本路径。