How to use OpenAPI 3.0 response “links” in Swagger UI?

断了今生、忘了曾经 提交于 2019-12-10 07:26:27

问题


I'm writing an Open API 3.0 spec and trying to get response links to render in Swagger UI v 3.18.3.

Example:

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

renders a link like this:

Is this expected? I ask because the operationId is exposed on the UI and parameters is shown as a JSON reference make it seem like something is not displaying properly. I would have expected a hyperlink or something to take me to the appropriate section in the Swagger web page that corresponds to the API being referenced by the link.


回答1:


Yes this is how Swagger UI currently renders OAS3 links. Rendering of links is one of the things on their OAS3 support backlog:

OAS 3.0 Support Backlog
This is a collection ticket for OAS3 specification features that are not yet supported by Swagger-UI.
...
[  ] Links can't be used to stage another operation
[  ] Link-level servers are not available for executing requests



来源:https://stackoverflow.com/questions/55839466/how-to-use-openapi-3-0-response-links-in-swagger-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!