redoc icon indicating copy to clipboard operation
redoc copied to clipboard

Support rendering OpenAPI 3 Link Objects

Open slashsbin opened this issue 7 years ago • 2 comments

It would be nice that ReDoc renders Link Objects to relate attributes with other endpoints.

Sample Link object:

paths:
  /users/{id}:
    parameters:
    - name: id
      in: path
      required: true
      description: the user identifier, as userId 
      schema:
        type: string
    get:
      responses:
        '200':
          description: the user being returned
          content:
            application/json:
              schema:
                type: object
                properties:
                  uuid: # the unique user id
                    type: string
                    format: uuid
          links:
            address:
              # the target link operationId
              operationId: getUserAddress
              parameters:
                # get the `id` field from the request path parameter named `id`
                userId: $request.path.id
  # the path item of the linked operation
  /users/{userid}/address:
    parameters:
    - name: userid
      in: path
      required: true
      description: the user identifier, as userId 
      schema:
        type: string
    # linked operation
    get:
      operationId: getUserAddress
      responses:
        '200':
          description: the user's address

slashsbin avatar Jul 22 '18 08:07 slashsbin

Help wanted here 🤔 UI mockup would help a lot 🙇

RomanHotsiy avatar Sep 10 '18 14:09 RomanHotsiy

here's a more complete example with the links having either an operationId or an operationRef and navigating around different links

openapi: '3.0.3'
info:
  title: 'test'
  version: '1'
servers:
  - url: 'https://www.stackoverflow.com/v1'
paths:
  '/thing':
    get:
      summary: thing api
      operationId: thing
      responses:
        '200':
          description: Successful response
          headers:
            message-id:
              schema:
                type: string
          links:
            thingId:
              description: get a thing object by thingId using an operationId link object
              operationId: getThingID
              parameters:
                id: $response.body#/thingId
                header_messageId: $request.header.message-id
            thingRef:
              description: get a thing object by thingId using an operationRef link object
              operationRef: '#/paths/~1thing~1{id}/get'
              parameters:
                id: $response.body#/thingId
          content:
            application/json:
              schema:
                type: object
                properties:
                  thingId:
                    type: string
                  thingName:
                    type: string
  '/thing/{id}':
    parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      - name: message-id
        in: header
        schema:
          type: string
    get:
      summary: thing with id api
      operationId: getThingID
      responses:
        '200':
          description: Successful response
          headers:
            message-id:
              schema:
                type: string
          links:
            thingId:
              description: modify a thing with a link object by operationId
              operationId: putThingID
              parameters:
                id: $request.path.id
                header_messageId: $request.header.message-id
              requestBody:
                thingAge: 10
            thingRef:
              description: a link object by operationRef
              operationRef: '#/paths/~1thing~1{id}/put'
              parameters:
                id: $request.path.id
              requestBody:
                thingAge: 10
          content:
            application/json:
              schema:
                type: object
                properties:
                  thingId:
                    type: string
                  thingName:
                    type: string
    put:
      summary: thing with id api
      operationId: putThingID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                thingId:
                  type: string
                thingName:
                  type: string
                thingAge:
                  type: number
      responses:
        '202':
          description: Successful response
          headers:
            message-id:
              schema:
                type: string
          links:
            thingId:
              description: a link object by operationId
              operationId: getThingID
              parameters:
                id: $request.path.id
                header_messageId: $request.header.message-id
            thingRef:
              description: a link object by operationRef
              operationRef: '#/paths/~1thing~1{id}/get'
              parameters:
                id: $request.path.id
          content:
            application/json:
              schema: {}

jeremyfiel avatar Dec 15 '23 04:12 jeremyfiel