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

问题描述 投票:2回答:1

我正在编写Open API 3.0规范并尝试在Swagger UI v 3.18.3中渲染response links

例:

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

呈现如下链接:

Response Link Example

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

swagger swagger-ui openapi
1个回答
1
投票

是的,这就是Swagger UI目前如何渲染OAS3 links。渲染linkstheir OAS3 support backlog上的事情之一:

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

© www.soinside.com 2019 - 2024. All rights reserved.