【问题标题】:How to use OpenAPI 3.0 response "links" in Swagger UI?如何在 Swagger UI 中使用 OpenAPI 3.0 响应“链接”?
【发布时间】:2021-11-23 20:13:36
【问题描述】:

我正在编写 Open API 3.0 规范并尝试让 response links 在 Swagger UI v 3.18.3 中呈现。

例子:

openapi: 3.0.0
info:
  title: Test
  version: '1.0'
tags: 
  - name: Artifacts
paths:
  /artifacts:
    post:
      tags: 
        - Artifacts
      operationId: createArtifact
      requestBody:
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
      responses:
        201:
          description: create
          headers:
            Location:
              schema:
                type: string
                format: uri
                example: /artifacts/100
          content:
            application/json:
              schema:
                type: object
                properties:
                  artifactId:
                    type: integer
                    format: int64
          links:
            Read Artifact:
              operationId: getArtifact
              parameters:
                artifact-id: '$response.body#/artifactId'
  /artifacts/{artifact-id}:
    parameters:
      - name: artifact-id
        in: path
        required: true
        schema:
          type: integer
          format: int64
    get:
      tags: 
        - Artifacts
      operationId: getArtifact
      responses:
        200:
          description: read
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary

呈现这样的链接:

这是预期的吗?我问是因为operationId 暴露在 UI 上,parameters 显示为 JSON 引用,这使得它看起来好像没有正确显示。我本来希望有一个超链接或其他东西将我带到 Swagger 网页中与链接所引用的 API 相对应的相应部分。

【问题讨论】:

    标签: swagger swagger-ui openapi


    【解决方案1】:

    是的,这就是 Swagger UI 当前呈现 OAS3 links 的方式。 links 的渲染是 their OAS3 support backlog 上的事情之一:

    OAS 3.0 支持积压
    这是 Swagger-UI 尚不支持的 OAS3 规范功能的集合票。
    ...
    [ ] 链接不能用于暂存其他操作
    [ ] 链接级服务器不可用于执行请求

    【讨论】:

    • 目前有没有支持链接的OAS3 UI/Editor?
    • @Carlton 如果您的意思是以某种有意义/有用的方式显示links - 我不知道有任何 OpenAPI 文档渲染器可以做到这一点。
    猜你喜欢
    • 1970-01-01
    • 2019-09-07
    • 1970-01-01
    • 2021-06-03
    • 2020-05-09
    • 2020-08-30
    • 2020-02-26
    • 2021-12-22
    相关资源
    最近更新 更多