search cancel

After creating a VSI from swagger, how to handle a Json array with multiple items

book

Article ID: 255991

calendar_today

Updated On:

Products

Service Virtualization

Issue/Introduction

If the Swagger Json file, that is used for creating a VSI, has an array in the request with multiple items, this request is not matched. 
For example if the request has 2 items, this is not matched: 

  "emp": ["John", "Gopal"]
}

Environment

Release : 10.7.2

Cause

A Swagger Json file, that has an array in the request, results in a VSI with only one item in the request. 

For example if the Swagger has the following array definition:
"emp": {
  "type": "array",
  "description": "Employee names",
  "items":  {
    "type": "string",
    "example": "John"
  },
  "maxitems": 100,
  "minitems": 1
}

Then the VSI has one argument: emp_0

If the actual request that is sent has two items, then this VSI will not match. 

Resolution

To allow multiple items in the request, just add arguments to the request in the VSI:
For example: emp_1, emp_2 etc.

Notes: 
- The "Select to Match" column can be used if only some of the items in the array are required.
- The "Magic String" column can be used to configure properties for those items that need to be used in the response. 
These will then be named {{request_emp_0}} and {{request_emp_1}} etc.