【问题标题】:Customize the message returned when accessing the server url of a connexion (python) service自定义访问 connexion (python) 服务的服务器 url 时返回的消息
【发布时间】:2020-10-01 11:00:34
【问题描述】:

我正在用connexion 编写一个python 服务。我可以通过localhost:<port>/ui 访问该服务的 swagger gui。但是,当我在浏览器中输入 localhost:<port> 而没有 /uiautomatically 由 connexion 添加)时,我收到以下消息:

{
  "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"
}

是否可以自定义此消息?就我而言,我希望 localhost:<port> 改为返回以下消息:

{"message": "check /ui to have access to the Swagger UI"}

【问题讨论】:

    标签: api rest service python-3.6 connexion


    【解决方案1】:

    我想我找到了解决办法。只需将以下内容添加到 openspec api:

      /:
        get:
          operationId: path.to.function
          summary: "my personlized message"
          responses:
          ......
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      • 2015-09-03
      • 1970-01-01
      • 1970-01-01
      • 2023-02-10
      相关资源
      最近更新 更多