首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置OpenAPI如何用参数重定向响应?

设置OpenAPI如何用参数重定向响应?
EN

Stack Overflow用户
提问于 2020-09-08 11:31:58
回答 1查看 3.9K关注 0票数 10

我有一个HTTP302(重定向),它实现了一个新的状态参数,它将附加到RedirectURL中,因此可以显示如下所示的消息

如果调用URL作为

代码语言:javascript
复制
GET http://localhost:8080/info/status?redirectUrl=http://localhost:8080/redirect

然后它将重定向为

代码语言:javascript
复制
http://localhost:8080/redirect?status=success

它是对应的

代码语言:javascript
复制
http://localhost:8080/redirect?status=error

但是如何在OpenAPI规范中描述这一点呢?我似乎无法在响应中使用parameters,并且找到了一些使用responseParameters的代码,但是我没有运气让它工作。甚至不知道这是否是受支持的东西,至少我没有发现用这两个命令编译的错误

代码语言:javascript
复制
  /info/setup:
    get:
      summary: Setup Url
      description: Setup Url to create new setup. Should be retrieved from api
        apps endpoint and redirect to, not called directly by the url defined
        here
      parameters:
        - in: query
          name: installationId
          description: The installation id
          required: true
          schema:
            type: string
        - in: query
          name: redirectUrl
          description: Url to redirect back to upon finished installation
          required: true
          schema:
            type: string
      responses:
        "302":
          description: Redirect
          responseParameters:
            - in: query
              name: status
              description: the status of the instalation
              schema:
                oneOf:
                  - type: string
                    example: success
                    description: When the installation was successful
                  - type: string
                    example: error
                    description: When the installation was erroneous
          headers:
            location:
              description: Setup state based redirect
              schema:
                oneOf:
                  - type: string
                    description: If setup is done and valid for installation id, will
                      redirect to given redirect url
                  - type: string
                    description: If no setup exist for installation id, will redirect to
                      SumUp oauth page
                  - type: string
                    description: If error during authorization with SumUpl, e.g. non
                      matching editions, will redirect to a setup page for
                      further user action

发生这种情况的共同方式是什么?

我们应该有两个重定向的URL,比如

代码语言:javascript
复制
GET http://localhost:8080/info/status
   ?redirectUrl=http://localhost:8080/redirect
   &errorUrl=http://localhost:8080/redirect_error

我对这个简单的困境有点不知所措,也许有人能帮上忙

EN

回答 1

Stack Overflow用户

发布于 2021-12-23 14:24:11

是的,这对OpenAPI来说是个恼人的问题。不能真正显式地指定重定向。

您所能做的最好是在3xx重定向范围(301、302、303、307、308)中指定状态代码的响应,该响应具有"string“类型的"location”标头参数。

然后,你应该添加一个描述和总结--基本上是你已经做过的事情。

OpenAPI规范github:https://github.com/OAI/OpenAPI-Specification/issues/2512中存在这个问题

希望很快就能做点什么。

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

https://stackoverflow.com/questions/63792987

复制
相关文章

相似问题

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