如何在 Swagger UI 中使用 OpenAPI 3.0 响应“链接”?

aka*_*xer 10 swagger swagger-ui openapi

我正在编写 Open API 3.0 规范并尝试获取响应链接以在 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
Run Code Online (Sandbox Code Playgroud)

呈现这样的链接:

响应链接示例

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

Hel*_*len 7

是的,这就是 Swagger UI 当前呈现 OAS3 的方式links。渲染links他们 OAS3 支持积压的事情之一:

OAS 3.0 Support Backlog
这是一张 Swagger-UI 尚不支持的 OAS3 规范功能的集合票。
...
[ ] 链接不能用于执行另一个操作
[ ] 链接级服务器不可用于执行请求

  • 目前有支持链接的 OAS3 UI/编辑器吗? (3认同)
  • @Carlton如果你的意思是以某种有意义/有用的方式显示“链接” - 我不知道有任何 OpenAPI 文档渲染器可以做到这一点。 (2认同)