Create Virtual Services from Swagger (OpenAPI)

ldt Portal lets you create a virtual service from a Swagger (OpenAPI)  2.0 or 3.0 document.
dts105-10-4
DevTest
 Portal lets you create a virtual service from a Swagger (OpenAPI)  2.0 or 3.0 document.
Assume that you want to virtualize a service that is in the early stages of development. You might not be able to create the virtual service by recording. However, if you have access to a Swagger (OpenAPI) document that describes the service, you can use this approach.
The following graphic shows the
Configure Connection & Resources
dialog, which lets you customize which operations to include.
Screen capture of Configure Connection and Resources dialog.
This procedure assumes that a virtual service environment (VSE) and 
DevTest
Portal are running.
If a
Responses
object in the document has a single HTTP response code that is set to
default
, the response code is mapped to the value 200.
You can create a virtual service from an OpenAPI 3.0 document using the same features that were present in Swagger 2.0. New features that were added as part of OpenAPI 3.0 are not supported.
If you are using the
$ref
keyword to reference a definition, the string value must begin with a relative path, such as "
./
" or "
../
".
You can test this feature with the Forward Cars demo application. Forward Cars includes a Swagger 2.0 document that describes the inventory service. The document is available at the following URL:
http://localhost:3500/cars-inventory/swagger.json
If Forward Cars is running on another computer, replace
localhost
with the host name or IP address of the other computer.
The Swagger document is also available in the
Data
folder of the
examples
project. The file name is
cars-inventory-swagger.json
.
The following video demonstrates this feature.

Follow these steps:
  1. Select
    Create
    ,
    Virtual Service
    from the left navigation menu.
  2. Click
    Specification
    .
  3. Provide basic information about the virtual service:
    1. Select the 
      VSE
      server.
    2. Enter a name for the virtual service.
    3. (Optional) Enter a description of the virtual service.
  4. Specify one or more Swagger documents by using any of the following approaches:
    • Enter a URL that points to a Swagger document.
      The URL must be accessible from the 
      VSE
      server that you selected.
    • Click
      Select File
      and select a Swagger document.
    • Click
      Select File
      and select a zip file that contains one or more Swagger documents.
  5. Click
    Continue
    .
    The
    Configure Connection & Resources
    dialog appears.
  6. You can customize which operations are included. For example, you can remove one of the operations in a set of three. You can also change the MIME type of the request and response. Depending on the contents of the Swagger document, only one MIME type might be available. When you are done with this dialog, click
    Finish
    .
  7. View and edit transactions.
  8. (Optional) Select one or more data protocols.
  9. If you selected at least one data protocol, configure each one.
  10. Save the virtual service.
All query arguments and request header values are included in the generated virtual service regardless of the value of the require flag that is indicated in the Swagger document being parsed.
So, for example, in the following snippet of a Swagger document:
{
"name": "patentDocId",
"in": "query",
"description": "patent id to filter the results (eg. 05569676)",
"required": "false",
"type": "string",
},
The query argument
patentDocId
has a required flag equal to
false
. Regardless of that condition, the indicated query argument will be included as an argument on the generated virtual service.
All query arguments are included in the virtual service. You must edit the virtual service to remove any query arguments you do not want to include.