Forum Discussion

MichaelBek's avatar
MichaelBek
Regular Visitor
4 years ago

OpenAPI 3.0 Links feature issue

Hello,

I'm a beginner in Swagger UI and would be grateful for any assistance.
I need to login to the device, obtain the sessionID from the server response HTTP header
and include this sessionID in the HTTP header of all subsequent requests.

Here's an example of login request and response I received from the server:

 

GET /System.xml?action=login&user=mike&password=mike123 HTTP/1.1
Accept: text/plain, */*; q=0.01
Accept-Language: en-US,en;q=0.7,he;q=0.3
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko
Host: 10.5.226.150
Connection: Keep-Alive

 

HTTP/1.1 200 OK
Content-Type: text/xml
Expires: Thu Oct 15 13:12:29 2020
Date: Thu Oct 15 13:12:29 2020
X-XSS-Protection: 1; mode=block
Content-Security-Policy: frame-ancestors 'self'
Cache-control: no-cache
Pragma: no-cache
Accept-Ranges: bytes
Connection: close
X-Frame-Options: SAMEORIGIN
csrftoken: 91957182
sessionID: UserId=10.6.202.229&17f716e17ee64554f9a05c9ad2077fd5&;path=/

 

<?xml version='1.0' encoding='UTF-8'?>
<ResponseData>
<ActionStatus>
<version>1.0</version>
<requestURL>/System.xml</requestURL>
<statusCode>0</statusCode>
<deviceStatusCode>0</deviceStatusCode>
<statusString>OK</statusString>
</ActionStatus>
</ResponseData>

 

In this way I should send this sessionID with all subsequent requests:


GET /device/authenticate_user.xml HTTP/1.1
Content-Type: text/plain
Accept: */*
sessionID: UserId=10.6.202.229&17f716e17ee64554f9a05c9ad2077fd5&;path=/
Accept-Language: en-US,en;q=0.7,he;q=0.3
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko
Host: 10.5.226.150
Connection: Keep-Alive


I use the OpenAPI 3.0 Links feature but it doesn't work.
The sessionID of /device/authenticate_user.xml Get header is not populated automatically from the sessionID of Login response.
What is wrong in my code below?

...
paths:
/System.xml:
get:
tags:
- Login
summary: Login request.
description: >-
The server response includes a sessionID in HTTP header in case of successful authentication.
parameters:
- name: action
in: query
description: login action
required: true
schema:
type: string
enum:
- login
- logout
example: login
- name: user
in: query
description: login username
required: true
schema:
type: string
example: mike
- name: password
in: query
description: login password
required: true
schema:
type: string
example: mike123
responses:
'200':
description: An XML object
headers:
sessionID:
schema:
type: string
description: The sessionID returned by the server after successful authentication
content:
application/xml:
schema:
$ref: '#/components/schemas/ResponseData'
# -----------------------------------------------------
# Links
# -----------------------------------------------------
links:
GetNewSessionID: # <---- Name of the link
operationId: getSessionID
parameters:
sessionID: '$response.header.sessionID'
description: >
The `sessionID` should be returned in the server response
# -------------------------------------------------------------
/device/authenticate_user.xml:
get:
tags:
- Keep-alive request
summary: Keep-alive request
operationId: getSessionID
parameters:
- in: header
name: sessionID
schema:
type: string
required: true
responses:
'200':
description: An XML object
content:
application/xml:
schema:
$ref: '#/components/schemas/ResponseData'

It works fine when I copy-paste sessionID from the Login response to the latest Get headers.
Is it possible to avoid a manual sessionID input?

The full code example is attached.


Best regards,

Michael

No RepliesBe the first to reply