Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use OpenAPI 3.0 response "links" in Swagger UI?

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:

Response Link Example

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.

like image 356
akagixxer Avatar asked Apr 24 '19 22:04

akagixxer


1 Answers

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

like image 192
Helen Avatar answered Oct 26 '22 15:10

Helen