Forum Discussion

rupert160's avatar
rupert160
New Member
4 years ago

Using Links to extract Authentication Tokens for other operations

I have been attempting to write an OAS 3.0.0 spec using the swagger links documentation however after many attempts (checking spelling mistakes etc), I cannot get the authentication token to populate the get URL of subsequent steps. This was YAML file that got me closest to an answer I thought. Any help to correct this would be appreciated:

 

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Testing
  license:
    name: MIT
servers:
  - url: http://localhost:8080
paths:
  /auth/login02?dlUser={dlUser}&dlPwd={dlPwd}:
    get:
      summary: Get login api token
      operationId: getLoginToken
      parameters:
        - name: dlUser
          in: path
          description: login user
          required: true
          schema:
            type: string
            example: "bob"
        - name: dlPwd
          in: path
          description: login password
          required: true
          schema:
            type: string
            example: "bobs-pass"
      responses:
        '200':
          description: JSON output from Login
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Login"
          links:
            authToken:
              $ref: '#/components/links/AuthToken'
          
  /home/overview/home.overview?dlAuth={dlAuth}:
    get:
      summary: Get content for Overview page
      operationId: showOverview
      parameters:
        - name: dlAuth
          in: path
          description: login authentication string
          required: true
          schema:
            type: string
            example: authToken
      responses:
        '200':
          description: JSON output from API
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Overview"
components:
  links:
    AuthToken:
      operationId: showOverview
      parameters:
        dlAuth: '$response.body#/resultData/authToken'
      description: >
            The `authToken` value returned in the response can be used as
            the `dlAuth` parameter in `GET /home/overview/home.overview?dlAuth={dlAuth}`.
  schemas:
    Overview:
      type: object
      properties:
        result_status: 
          type: integer
          example: 1
        result_data:
          type: object
          properties:
            overviewId: 
              type: integer
              example: 2
            stateName: 
              type: string
              example: "home.overview"
            pageContent:
              type: string
              example: "<div>hello</div>"
    Login:
      type: object
      properties:
        resultStatus: 
          type: integer
          example: 1
        resultData:
          type: object
          properties:
            authToken: 
              type: string
              example: "081D3D749383BAAC27AB3BBBDB6D5575"
            userFirstName:
              type: string
              example: "bob"

 

No RepliesBe the first to reply